Commit fe962b12 authored by Naoyuki Kanezawa's avatar Naoyuki Kanezawa Committed by Guillermo Rauch

make sure to flush styles and head (#459)

parent 4faa281f
...@@ -6,12 +6,18 @@ import flush from 'styled-jsx/server' ...@@ -6,12 +6,18 @@ import flush from 'styled-jsx/server'
export default class Document extends Component { export default class Document extends Component {
static getInitialProps ({ renderPage }) { static getInitialProps ({ renderPage }) {
let head let head
const { html, css, ids } = renderStatic(() => { let rendered
const page = renderPage() let styles
head = page.head try {
return page.html rendered = renderStatic(() => {
}) const page = renderPage()
const styles = flush() head = page.head
return page.html
})
} finally {
styles = flush()
}
const { html, css, ids } = rendered
const nextCSS = { css, ids, styles } const nextCSS = { css, ids, styles }
return { html, head, nextCSS } return { html, head, nextCSS }
} }
......
...@@ -62,8 +62,15 @@ async function doRender (req, res, pathname, query, { ...@@ -62,8 +62,15 @@ async function doRender (req, res, pathname, query, {
router: new Router(pathname, query) router: new Router(pathname, query)
}) })
const html = (staticMarkup ? renderToStaticMarkup : renderToString)(app) const render = staticMarkup ? renderToStaticMarkup : renderToString
const head = Head.rewind() || defaultHead()
let html
let head
try {
html = render(app)
} finally {
head = Head.rewind() || defaultHead()
}
return { html, head } return { html, head }
} }
......
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