1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

make sure to flush styles and head (#459)

This commit is contained in:
Naoyuki Kanezawa 2016-12-22 00:57:25 +09:00 committed by Guillermo Rauch
parent 4faa281f23
commit fe962b12de
2 changed files with 21 additions and 8 deletions

View file

@ -6,12 +6,18 @@ import flush from 'styled-jsx/server'
export default class Document extends Component {
static getInitialProps ({ renderPage }) {
let head
const { html, css, ids } = renderStatic(() => {
const page = renderPage()
head = page.head
return page.html
})
const styles = flush()
let rendered
let styles
try {
rendered = renderStatic(() => {
const page = renderPage()
head = page.head
return page.html
})
} finally {
styles = flush()
}
const { html, css, ids } = rendered
const nextCSS = { css, ids, styles }
return { html, head, nextCSS }
}

View file

@ -62,8 +62,15 @@ async function doRender (req, res, pathname, query, {
router: new Router(pathname, query)
})
const html = (staticMarkup ? renderToStaticMarkup : renderToString)(app)
const head = Head.rewind() || defaultHead()
const render = staticMarkup ? renderToStaticMarkup : renderToString
let html
let head
try {
html = render(app)
} finally {
head = Head.rewind() || defaultHead()
}
return { html, head }
}