-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix unstyled text visible after splash screen
- Loading branch information
1 parent
9be7b1f
commit 68dd21b
Showing
3 changed files
with
82 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import styled from 'styled-components'; | ||
|
||
const LoadingWrapper = styled.div` | ||
background-color: #0000; | ||
`; | ||
|
||
const Loading = () => <LoadingWrapper />; | ||
|
||
export default Loading; |
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
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// _document.tsx | ||
import Document, { Html, Head, Main, NextScript, DocumentContext, DocumentInitialProps } from 'next/document'; | ||
import { ServerStyleSheet } from 'styled-components'; | ||
|
||
class MyDocument extends Document { | ||
static async getInitialProps(ctx: DocumentContext): Promise<DocumentInitialProps> { | ||
const sheet = new ServerStyleSheet(); | ||
const originalRenderPage = ctx.renderPage; | ||
|
||
try { | ||
ctx.renderPage = () => | ||
originalRenderPage({ | ||
enhanceApp: (App) => (props) => sheet.collectStyles(<App {...props} />), | ||
}); | ||
|
||
const initialProps = await Document.getInitialProps(ctx); | ||
return { | ||
...initialProps, | ||
styles: ( | ||
<> | ||
{initialProps.styles} | ||
{sheet.getStyleElement()} | ||
</> | ||
), | ||
}; | ||
} finally { | ||
sheet.seal(); | ||
} | ||
} | ||
|
||
render() { | ||
return ( | ||
<Html> | ||
<Head> | ||
<link rel="preload" href="/_next/static/css/antd.css" as="style" /> | ||
<link rel="stylesheet" href="/_next/static/css/antd.css" /> | ||
</Head> | ||
<body> | ||
<Main /> | ||
<NextScript /> | ||
</body> | ||
</Html> | ||
); | ||
} | ||
} | ||
|
||
export default MyDocument; |