-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "fix(antd-css): extract styles to avoid flush (#1057)"
This reverts commit 6fcbd8d.
- Loading branch information
1 parent
6fcbd8d
commit c475f5b
Showing
2 changed files
with
16 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,6 @@ | |
"codecov", | ||
"codesandbox", | ||
"combobox", | ||
"cssinjs", | ||
"flexbugs", | ||
"gemoji", | ||
"instanceof", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,19 @@ | ||
import { getSandpackCssText } from '@codesandbox/sandpack-react'; | ||
import Document, { | ||
Head, | ||
Html, | ||
Main, | ||
NextScript, | ||
DocumentContext, | ||
} from 'next/document'; | ||
import { createCache, extractStyle, StyleProvider } from '@ant-design/cssinjs'; | ||
import { Head, Html, Main, NextScript } from 'next/document'; | ||
|
||
export default class CustomDocument extends Document { | ||
static async getInitialProps(ctx: DocumentContext) { | ||
const cache = createCache(); | ||
const originalRenderPage = ctx.renderPage; | ||
const Document = (): JSX.Element => ( | ||
<Html> | ||
<Head> | ||
<style | ||
id="sandpack" | ||
dangerouslySetInnerHTML={{ __html: getSandpackCssText() }} | ||
/> | ||
</Head> | ||
<body> | ||
<Main /> | ||
<NextScript /> | ||
</body> | ||
</Html> | ||
); | ||
|
||
ctx.renderPage = () => | ||
originalRenderPage({ | ||
enhanceApp: App => props => | ||
( | ||
<StyleProvider cache={cache}> | ||
<App {...props} /> | ||
</StyleProvider> | ||
), | ||
}); | ||
|
||
const initialProps = await Document.getInitialProps(ctx); | ||
|
||
return { | ||
...initialProps, | ||
styles: ( | ||
<> | ||
{initialProps.styles} | ||
<style | ||
data-test="extract" | ||
dangerouslySetInnerHTML={{ __html: extractStyle(cache) }} | ||
/> | ||
<style | ||
id="sandpack" | ||
dangerouslySetInnerHTML={{ __html: getSandpackCssText() }} | ||
/> | ||
</> | ||
), | ||
}; | ||
} | ||
|
||
render() { | ||
return ( | ||
<Html> | ||
<Head /> | ||
<body> | ||
<Main /> | ||
<NextScript /> | ||
</body> | ||
</Html> | ||
); | ||
} | ||
} | ||
export default Document; |