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

Fix handling finished response (#889)

* allows to not return props if response is already finished on getInitialProps

* check res.finished after getInitialProps call of Document
This commit is contained in:
Naoyuki Kanezawa 2017-01-26 20:06:50 +09:00 committed by Arunoda Susiripala
parent 386c960359
commit 0b3db91731
2 changed files with 3 additions and 1 deletions

View file

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

View file

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