Skip to content

Commit 6845e76

Browse files
committed
try lazy loading on all
1 parent 8cca337 commit 6845e76

File tree

3 files changed

+71
-5
lines changed

3 files changed

+71
-5
lines changed

packages/docusaurus-theme-openapi-docs/src/theme/ParamsDetails/index.tsx

+34-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* LICENSE file in the root directory of this source tree.
66
* ========================================================================== */
77

8-
import React from "react";
8+
import React, { Suspense, useEffect, useState } from "react";
99

1010
import Details from "@theme/Details";
1111
import ParamsItem from "@theme/ParamsItem";
@@ -14,7 +14,28 @@ interface Props {
1414
parameters: any[];
1515
}
1616

17-
const ParamsDetails: React.FC<Props> = ({ parameters }) => {
17+
const ParamsDetailsComponent: React.FC<Props> = ({ parameters }) => {
18+
const [isClient, setIsClient] = useState(false);
19+
20+
useEffect(() => {
21+
if (typeof window !== "undefined") {
22+
setIsClient(true);
23+
}
24+
}, []);
25+
26+
if (!isClient) {
27+
return (
28+
<div className="openapi-explorer__loading-container">
29+
<div className="openapi-response__lds-ring">
30+
<div></div>
31+
<div></div>
32+
<div></div>
33+
<div></div>
34+
</div>
35+
</div>
36+
);
37+
}
38+
1839
const types = ["path", "query", "header", "cookie"];
1940

2041
return (
@@ -66,4 +87,15 @@ const ParamsDetails: React.FC<Props> = ({ parameters }) => {
6687
);
6788
};
6889

90+
const ParamsDetails: React.FC<Props> = (props) => {
91+
const LazyComponent = React.lazy(() =>
92+
Promise.resolve({ default: ParamsDetailsComponent })
93+
);
94+
return (
95+
<Suspense fallback={<div>Loading...</div>}>
96+
<LazyComponent {...props} />
97+
</Suspense>
98+
);
99+
};
100+
69101
export default ParamsDetails;

packages/docusaurus-theme-openapi-docs/src/theme/RequestSchema/index.tsx

+34-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* LICENSE file in the root directory of this source tree.
66
* ========================================================================== */
77

8-
import React from "react";
8+
import React, { Suspense, useEffect, useState } from "react";
99

1010
import Details from "@theme/Details";
1111
import MimeTabs from "@theme/MimeTabs"; // Assume these components exist
@@ -26,7 +26,28 @@ interface Props {
2626
};
2727
}
2828

29-
const RequestSchema: React.FC<Props> = ({ title, body, style }) => {
29+
const RequestSchemaComponent: React.FC<Props> = ({ title, body, style }) => {
30+
const [isClient, setIsClient] = useState(false);
31+
32+
useEffect(() => {
33+
if (typeof window !== "undefined") {
34+
setIsClient(true);
35+
}
36+
}, []);
37+
38+
if (!isClient) {
39+
return (
40+
<div className="openapi-explorer__loading-container">
41+
<div className="openapi-response__lds-ring">
42+
<div></div>
43+
<div></div>
44+
<div></div>
45+
<div></div>
46+
</div>
47+
</div>
48+
);
49+
}
50+
3051
if (
3152
body === undefined ||
3253
body.content === undefined ||
@@ -142,4 +163,15 @@ const RequestSchema: React.FC<Props> = ({ title, body, style }) => {
142163
);
143164
};
144165

166+
const RequestSchema: React.FC<Props> = (props) => {
167+
const LazyComponent = React.lazy(() =>
168+
Promise.resolve({ default: RequestSchemaComponent })
169+
);
170+
return (
171+
<Suspense fallback={<div>Loading...</div>}>
172+
<LazyComponent {...props} />
173+
</Suspense>
174+
);
175+
};
176+
145177
export default RequestSchema;

packages/docusaurus-theme-openapi-docs/src/theme/ResponseSchema/index.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ const ResponseSchemaComponent: React.FC<Props> = ({
4040
const [isClient, setIsClient] = useState(false);
4141

4242
useEffect(() => {
43-
setIsClient(true);
43+
if (typeof window !== "undefined") {
44+
setIsClient(true);
45+
}
4446
}, []);
4547

4648
if (!isClient) {

0 commit comments

Comments
 (0)