| 4 | import { defaultCSSTheme } from 'components/hooks/useTheme' |
| 5 | |
| 6 | export default class MyDocument extends Document { |
| 7 | static async getInitialProps(ctx: DocumentContext) { |
| 8 | const sheet = new ServerStyleSheet() |
| 9 | const originalRenderPage = ctx.renderPage |
| 10 | |
| 11 | try { |
| 12 | ctx.renderPage = () => |
| 13 | originalRenderPage({ |
| 14 | enhanceApp: (App) => (props) => sheet.collectStyles(<App {...props} />), |
| 15 | }) |
| 16 | |
| 17 | const initialProps = await Document.getInitialProps(ctx) |
| 18 | return { |
| 19 | ...initialProps, |
| 20 | styles: ( |
| 21 | <> |
| 22 | {initialProps.styles} |
| 23 | {sheet.getStyleElement()} |
| 24 | </> |
| 25 | ), |
| 26 | } |
| 27 | } finally { |
| 28 | sheet.seal() |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | render() { |
| 33 | return ( |
| 34 | <Html> |
| 35 | <Head /> |
| 36 | <body |
| 37 | // These values are always the SSR rendereding defaults. |
| 38 | // The will get updated later in a useEffect hook, in the client, |
| 39 | // in the MyApp component. |
| 40 | data-color-mode={defaultCSSTheme.colorMode} |
| 41 | data-light-theme={defaultCSSTheme.lightTheme} |
| 42 | data-dark-theme={defaultCSSTheme.darkTheme} |
| 43 | > |
| 44 | <Main /> |
| 45 | <NextScript /> |
| 46 | </body> |
| 47 | </Html> |
| 48 | ) |
| 49 | } |
| 50 | } |
nothing calls this directly
no outgoing calls
no test coverage detected