Skip to content

Commit

Permalink
try lazy loading on all
Browse files Browse the repository at this point in the history
  • Loading branch information
sserrata committed Oct 7, 2024
1 parent f5db8fd commit 0512243
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
* ========================================================================== */

import React from "react";
import React, { Suspense, useEffect, useState } from "react";

import Details from "@theme/Details";
import ParamsItem from "@theme/ParamsItem";
Expand All @@ -14,7 +14,28 @@ interface Props {
parameters: any[];
}

const ParamsDetails: React.FC<Props> = ({ parameters }) => {
const ParamsDetailsComponent: React.FC<Props> = ({ parameters }) => {
const [isClient, setIsClient] = useState(false);

useEffect(() => {
if (typeof window !== "undefined") {
setIsClient(true);
}
}, []);

if (!isClient) {
return (
<div className="openapi-explorer__loading-container">
<div className="openapi-response__lds-ring">
<div></div>
<div></div>
<div></div>
<div></div>
</div>
</div>
);
}

const types = ["path", "query", "header", "cookie"];

return (
Expand Down Expand Up @@ -66,4 +87,15 @@ const ParamsDetails: React.FC<Props> = ({ parameters }) => {
);
};

const ParamsDetails: React.FC<Props> = (props) => {
const LazyComponent = React.lazy(() =>
Promise.resolve({ default: ParamsDetailsComponent })
);
return (
<Suspense fallback={<div>Loading...</div>}>
<LazyComponent {...props} />
</Suspense>
);
};

export default ParamsDetails;
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
* ========================================================================== */

import React from "react";
import React, { Suspense, useEffect, useState } from "react";

import Details from "@theme/Details";
import MimeTabs from "@theme/MimeTabs"; // Assume these components exist
Expand All @@ -26,7 +26,28 @@ interface Props {
};
}

const RequestSchema: React.FC<Props> = ({ title, body, style }) => {
const RequestSchemaComponent: React.FC<Props> = ({ title, body, style }) => {
const [isClient, setIsClient] = useState(false);

useEffect(() => {
if (typeof window !== "undefined") {
setIsClient(true);
}
}, []);

if (!isClient) {
return (
<div className="openapi-explorer__loading-container">
<div className="openapi-response__lds-ring">
<div></div>
<div></div>
<div></div>
<div></div>
</div>
</div>
);
}

if (
body === undefined ||
body.content === undefined ||
Expand Down Expand Up @@ -142,4 +163,15 @@ const RequestSchema: React.FC<Props> = ({ title, body, style }) => {
);
};

const RequestSchema: React.FC<Props> = (props) => {
const LazyComponent = React.lazy(() =>
Promise.resolve({ default: RequestSchemaComponent })
);
return (
<Suspense fallback={<div>Loading...</div>}>
<LazyComponent {...props} />
</Suspense>
);
};

export default RequestSchema;
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ const ResponseSchemaComponent: React.FC<Props> = ({
const [isClient, setIsClient] = useState(false);

useEffect(() => {
setIsClient(true);
if (typeof window !== "undefined") {
setIsClient(true);
}
}, []);

if (!isClient) {
Expand Down

0 comments on commit 0512243

Please sign in to comment.