mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
Support for cxs rehydration and removal of duplicate styles. (#1860)
* add cxs.rehydrate. * add id='cxs-style'.
This commit is contained in:
parent
0abfca26f7
commit
23574b5489
|
@ -1,5 +1,5 @@
|
||||||
import Document, { Head, Main, NextScript } from 'next/document'
|
import Document, { Head, Main, NextScript } from 'next/document'
|
||||||
import cxs from 'cxs'
|
import cxs from 'cxs/lite'
|
||||||
|
|
||||||
export default class MyDocument extends Document {
|
export default class MyDocument extends Document {
|
||||||
static async getInitialProps ({ renderPage }) {
|
static async getInitialProps ({ renderPage }) {
|
||||||
|
@ -13,7 +13,7 @@ export default class MyDocument extends Document {
|
||||||
<html>
|
<html>
|
||||||
<Head>
|
<Head>
|
||||||
<title>My page</title>
|
<title>My page</title>
|
||||||
<style dangerouslySetInnerHTML={{ __html: this.props.style }} />
|
<style id='cxs-style' dangerouslySetInnerHTML={{ __html: this.props.style }} />
|
||||||
</Head>
|
</Head>
|
||||||
<body>
|
<body>
|
||||||
<Main />
|
<Main />
|
||||||
|
|
|
@ -1,5 +1,13 @@
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import cxs from 'cxs'
|
import cxs from 'cxs/lite'
|
||||||
|
|
||||||
|
// Using cxs/lite on both the server and client,
|
||||||
|
// the styles will need to be rehydrated.
|
||||||
|
if (typeof window !== 'undefined') {
|
||||||
|
const styleTag = document.getElementById('cxs-style')
|
||||||
|
const serverCss = styleTag.innerHTML
|
||||||
|
cxs.rehydrate(serverCss)
|
||||||
|
}
|
||||||
|
|
||||||
export default () => (
|
export default () => (
|
||||||
<div className={cx.root}>
|
<div className={cx.root}>
|
||||||
|
|
Loading…
Reference in a new issue