Commit 0b3db917 authored by Naoyuki Kanezawa's avatar Naoyuki Kanezawa Committed by Arunoda Susiripala

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
parent 386c9603
......@@ -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)
......
......@@ -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,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment