Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
1bf2b74f
Unverified
Commit
1bf2b74f
authored
Aug 15, 2024
by
lijianan
Committed by
GitHub
Aug 15, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
examples: avoid duplicate css insert for ant design (#57947)
Co-authored-by:
Lee Robinson
<
me@leerob.io
>
parent
fd90690a
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
18 deletions
+18
-18
AntdRegistry.tsx
examples/with-ant-design/app/AntdRegistry.tsx
+15
-11
layout.tsx
examples/with-ant-design/app/layout.tsx
+1
-5
package.json
examples/with-ant-design/package.json
+2
-2
No files found.
examples/with-ant-design/app/AntdRegistry.tsx
View file @
1bf2b74f
...
@@ -5,18 +5,22 @@ import { useServerInsertedHTML } from "next/navigation";
...
@@ -5,18 +5,22 @@ import { useServerInsertedHTML } from "next/navigation";
import
{
StyleProvider
,
createCache
,
extractStyle
}
from
"@ant-design/cssinjs"
;
import
{
StyleProvider
,
createCache
,
extractStyle
}
from
"@ant-design/cssinjs"
;
import
type
Entity
from
"@ant-design/cssinjs/es/Cache"
;
import
type
Entity
from
"@ant-design/cssinjs/es/Cache"
;
interface
StyledRegistryProps
{
const
StyledComponentsRegistry
=
({
children
}:
React
.
PropsWithChildren
)
=>
{
children
:
React
.
ReactNode
;
}
const
StyledComponentsRegistry
=
({
children
}:
StyledRegistryProps
)
=>
{
const
cache
=
React
.
useMemo
<
Entity
>
(()
=>
createCache
(),
[]);
const
cache
=
React
.
useMemo
<
Entity
>
(()
=>
createCache
(),
[]);
useServerInsertedHTML
(()
=>
(
const
isServerInserted
=
React
.
useRef
<
boolean
>
(
false
);
useServerInsertedHTML
(()
=>
{
// avoid duplicate css insert
if
(
isServerInserted
.
current
)
{
return
;
}
isServerInserted
.
current
=
true
;
return
(
<
style
<
style
id=
"antd"
id=
"antd"
dangerouslySetInnerHTML=
{
{
__html
:
extractStyle
(
cache
,
true
)
}
}
dangerouslySetInnerHTML=
{
{
__html
:
extractStyle
(
cache
,
true
)
}
}
/>
/>
));
);
});
return
<
StyleProvider
cache=
{
cache
}
>
{
children
}
</
StyleProvider
>;
return
<
StyleProvider
cache=
{
cache
}
>
{
children
}
</
StyleProvider
>;
};
};
...
...
examples/with-ant-design/app/layout.tsx
View file @
1bf2b74f
...
@@ -11,11 +11,7 @@ export const metadata: Metadata = {
...
@@ -11,11 +11,7 @@ export const metadata: Metadata = {
description
:
"Generated by create next app"
,
description
:
"Generated by create next app"
,
};
};
interface
RootLayoutProps
{
function
RootLayout
({
children
}:
React
.
PropsWithChildren
)
{
children
:
React
.
ReactNode
;
}
function
RootLayout
({
children
}:
RootLayoutProps
)
{
return
(
return
(
<
html
lang=
"en"
>
<
html
lang=
"en"
>
<
body
className=
{
inter
.
className
}
>
<
body
className=
{
inter
.
className
}
>
...
...
examples/with-ant-design/package.json
View file @
1bf2b74f
...
@@ -10,8 +10,8 @@
...
@@ -10,8 +10,8 @@
"@ant-design/icons"
:
"^5.1.4"
,
"@ant-design/icons"
:
"^5.1.4"
,
"antd"
:
"^5.0.0"
,
"antd"
:
"^5.0.0"
,
"next"
:
"latest"
,
"next"
:
"latest"
,
"react"
:
"18.2.0"
,
"react"
:
"
^
18.2.0"
,
"react-dom"
:
"18.2.0"
"react-dom"
:
"
^
18.2.0"
},
},
"devDependencies"
:
{
"devDependencies"
:
{
"@types/node"
:
"^20.4.5"
,
"@types/node"
:
"^20.4.5"
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment