Skip to content

fix: Hydration warnings / mismatched styles due to SSR #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions site/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,27 @@ const Contents: React.FC<AppProps> = ({ Component, pageProps }) => {
)
}

/**
* ClientRender is a component that only allows its children to be rendered
* client-side. This check is performed by querying the existence of the window
* global.
*/
const ClientRender: React.FC = ({ children }) => (
<div suppressHydrationWarning>{typeof window === "undefined" ? null : children}</div>
)

/**
* <App /> is the root rendering logic of the application - setting up our router
* and any contexts / global state management.
*/
const MyApp: React.FC<AppProps> = (appProps) => {
return (
<ThemeProvider theme={dark}>
<CssBaseline />
<Contents {...appProps} />
</ThemeProvider>
<ClientRender>
<ThemeProvider theme={dark}>
<CssBaseline />
<Contents {...appProps} />
</ThemeProvider>
</ClientRender>
)
}

Expand Down
33 changes: 33 additions & 0 deletions site/pages/_document.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import Document, { DocumentContext, Head, Html, Main, NextScript } from "next/document"
import React from "react"

class MyDocument extends Document {
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
static async getInitialProps(ctx: DocumentContext) {
const initialProps = await Document.getInitialProps(ctx)
return { ...initialProps }
}

render(): JSX.Element {
return (
<Html>
<Head>
<meta charSet="utf-8" />
<meta name="theme-color" content="#17172E" />
<meta name="application-name" content="Coder" />
<meta property="og:type" content="website" />
<meta property="csp-nonce" content="{{ .CSP.Nonce }}" />
<link crossOrigin="use-credentials" rel="mask-icon" href="/static/favicon.svg" color="#000000" />
<link rel="alternate icon" type="image/png" href="/static/favicon.png" />
<link rel="icon" type="image/svg+xml" href="/static/favicon.svg" />
</Head>
<body>
<Main />
<NextScript />
</body>
</Html>
)
}
}

export default MyDocument
Binary file added site/static/favicon.ico
Binary file not shown.
Binary file added site/static/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions site/static/favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.