Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions server/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
Expand Down
11 changes: 9 additions & 2 deletions server/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}

Expand Down