f8f308d6dd
This PR fixes https://github.com/vercel/next.js/issues/4883. It introduces a new global variable (`window.__REHYDRATE_IDS`) only when necessary. In the case of the `with-react-with-styles` example, rehydration isn't happening, so I removed the creation of the variable. In the case of the `with-react-intl` example, the information doesn't seem to be set anymore on `__NEXT_DATA__`, so I just removed the default reference to it.
43 lines
1.1 KiB
JavaScript
43 lines
1.1 KiB
JavaScript
import Document, { Html, Head, Main, NextScript } from 'next/document'
|
|
import { StyleSheetServer } from 'aphrodite'
|
|
|
|
class MyDocument extends Document {
|
|
static async getInitialProps({ renderPage }) {
|
|
const { html, css } = StyleSheetServer.renderStatic(() => renderPage())
|
|
const ids = css.renderedClassNames
|
|
return { ...html, css, ids }
|
|
}
|
|
|
|
render() {
|
|
/* Make sure to use data-aphrodite attribute in the style tag here
|
|
so that aphrodite knows which style tag it's in control of when
|
|
the client goes to render styles. If you don't you'll get a second
|
|
<style> tag */
|
|
const { css, ids } = this.props
|
|
return (
|
|
<Html>
|
|
<Head>
|
|
<style
|
|
data-aphrodite
|
|
dangerouslySetInnerHTML={{ __html: css.content }}
|
|
/>
|
|
</Head>
|
|
<body>
|
|
<Main />
|
|
<NextScript />
|
|
{ids && (
|
|
<script
|
|
dangerouslySetInnerHTML={{
|
|
__html: `
|
|
window.__REHYDRATE_IDS = ${JSON.stringify(ids)}
|
|
`,
|
|
}}
|
|
/>
|
|
)}
|
|
</body>
|
|
</Html>
|
|
)
|
|
}
|
|
}
|
|
|
|
export default MyDocument
|