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:
parent
386c960359
commit
0b3db91731
|
@ -46,7 +46,7 @@ export async function loadGetInitialProps (Component, ctx) {
|
||||||
if (!Component.getInitialProps) return {}
|
if (!Component.getInitialProps) return {}
|
||||||
|
|
||||||
const props = await Component.getInitialProps(ctx)
|
const props = await Component.getInitialProps(ctx)
|
||||||
if (!props) {
|
if (!props && (!ctx.res || !ctx.res.finished)) {
|
||||||
const compName = Component.displayName || Component.name
|
const compName = Component.displayName || Component.name
|
||||||
const message = `"${compName}.getInitialProps()" should resolve to an object. But found "${props}" instead.`
|
const message = `"${compName}.getInitialProps()" should resolve to an object. But found "${props}" instead.`
|
||||||
throw new Error(message)
|
throw new Error(message)
|
||||||
|
|
|
@ -83,6 +83,8 @@ async function doRender (req, res, pathname, query, {
|
||||||
|
|
||||||
const docProps = await loadGetInitialProps(Document, { ...ctx, renderPage })
|
const docProps = await loadGetInitialProps(Document, { ...ctx, renderPage })
|
||||||
|
|
||||||
|
if (res.finished) return
|
||||||
|
|
||||||
const doc = createElement(Document, {
|
const doc = createElement(Document, {
|
||||||
__NEXT_DATA__: {
|
__NEXT_DATA__: {
|
||||||
component,
|
component,
|
||||||
|
|
Loading…
Reference in a new issue