diff --git a/lib/utils.js b/lib/utils.js index 56047419..b1757f98 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -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) diff --git a/server/render.js b/server/render.js index 901b21b8..edee8c11 100644 --- a/server/render.js +++ b/server/render.js @@ -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,