Unverified Commit 1bf2b74f authored by lijianan's avatar lijianan Committed by GitHub

examples: avoid duplicate css insert for ant design (#57947)

Co-authored-by: 's avatarLee Robinson <me@leerob.io>
parent fd90690a
......@@ -5,18 +5,22 @@ import { useServerInsertedHTML } from "next/navigation";
import { StyleProvider, createCache, extractStyle } from "@ant-design/cssinjs";
import type Entity from "@ant-design/cssinjs/es/Cache";
interface StyledRegistryProps {
children: React.ReactNode;
}
const StyledComponentsRegistry = ({ children }: StyledRegistryProps) => {
const StyledComponentsRegistry = ({ children }: React.PropsWithChildren) => {
const cache = React.useMemo<Entity>(() => createCache(), []);
useServerInsertedHTML(() => (
<style
id="antd"
dangerouslySetInnerHTML={{ __html: extractStyle(cache, true) }}
/>
));
const isServerInserted = React.useRef<boolean>(false);
useServerInsertedHTML(() => {
// avoid duplicate css insert
if (isServerInserted.current) {
return;
}
isServerInserted.current = true;
return (
<style
id="antd"
dangerouslySetInnerHTML={{ __html: extractStyle(cache, true) }}
/>
);
});
return <StyleProvider cache={cache}>{children}</StyleProvider>;
};
......
......@@ -11,11 +11,7 @@ export const metadata: Metadata = {
description: "Generated by create next app",
};
interface RootLayoutProps {
children: React.ReactNode;
}
function RootLayout({ children }: RootLayoutProps) {
function RootLayout({ children }: React.PropsWithChildren) {
return (
<html lang="en">
<body className={inter.className}>
......
......@@ -10,8 +10,8 @@
"@ant-design/icons": "^5.1.4",
"antd": "^5.0.0",
"next": "latest",
"react": "18.2.0",
"react-dom": "18.2.0"
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/node": "^20.4.5",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment