Commit 23574b54 authored by Arana Jhonny's avatar Arana Jhonny Committed by Tim Neutkens

Support for cxs rehydration and removal of duplicate styles. (#1860)

* add cxs.rehydrate.

* add id='cxs-style'.
parent 0abfca26
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 { ...@@ -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 />
......
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}>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment