Skip to content

Commit

Permalink
Fix handling finished response (#889)
Browse files Browse the repository at this point in the history
* allows to not return props if response is already finished on getInitialProps

* check res.finished after getInitialProps call of Document
  • Loading branch information
nkzawa authored and arunoda committed Jan 26, 2017
1 parent 386c960 commit 0b3db91
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export async function loadGetInitialProps (Component, ctx) {
if (!Component.getInitialProps) return {}

const props = await Component.getInitialProps(ctx)
if (!props) {
if (!props && (!ctx.res || !ctx.res.finished)) {
const compName = Component.displayName || Component.name
const message = `"${compName}.getInitialProps()" should resolve to an object. But found "${props}" instead.`
throw new Error(message)
Expand Down
2 changes: 2 additions & 0 deletions server/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ async function doRender (req, res, pathname, query, {

const docProps = await loadGetInitialProps(Document, { ...ctx, renderPage })

if (res.finished) return

const doc = createElement(Document, {
__NEXT_DATA__: {
component,
Expand Down

0 comments on commit 0b3db91

Please sign in to comment.