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 { 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 }
} }

View file

@ -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 }
} }