Skip to content

Commit

Permalink
make sure to flush styles and head (#459)
Browse files Browse the repository at this point in the history
  • Loading branch information
nkzawa authored and rauchg committed Dec 21, 2016
1 parent 4faa281 commit fe962b1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
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

0 comments on commit fe962b1

Please sign in to comment.