-
Notifications
You must be signed in to change notification settings - Fork 582
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Hydration warnings / mismatched styles due to SSR (#31)
While starting on the create workspace flow - I noticed some weird CSS issues. In particular, intermittently, the web UI would render like this: ![image](https://user-images.githubusercontent.com/88213859/150072041-f1c6b9b2-941c-41a8-ad84-b7b163b3504f.png) ...and when that happened, there'd be an accompanying error in the console: ![image](https://user-images.githubusercontent.com/88213859/150072101-d98cb714-d133-4532-8a02-a7642d242a02.png) The issue is that NextJS is trying to render the page on the server and use the styles - and sometimes the classnames mismatch between server-side and client-side rendering. We actually worked around this in `cdr/m` with a `<SafeHydration />` component and a custom `_document.tsx` This change ports over both the component and custom `_document.tsx`. I noticed, in addition, I missed the favicons when switching to NextJS, so I brought those over too.
- Loading branch information
1 parent
6e6eee6
commit 36b7b20
Showing
5 changed files
with
49 additions
and
4 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
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,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 not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.