Skip to content

Commit 0b3db91

Browse files
nkzawaarunoda
authored andcommitted
Fix handling finished response (vercel#889)
* allows to not return props if response is already finished on getInitialProps * check res.finished after getInitialProps call of Document
1 parent 386c960 commit 0b3db91

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

lib/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export async function loadGetInitialProps (Component, ctx) {
4646
if (!Component.getInitialProps) return {}
4747

4848
const props = await Component.getInitialProps(ctx)
49-
if (!props) {
49+
if (!props && (!ctx.res || !ctx.res.finished)) {
5050
const compName = Component.displayName || Component.name
5151
const message = `"${compName}.getInitialProps()" should resolve to an object. But found "${props}" instead.`
5252
throw new Error(message)

server/render.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ async function doRender (req, res, pathname, query, {
8383

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

86+
if (res.finished) return
87+
8688
const doc = createElement(Document, {
8789
__NEXT_DATA__: {
8890
component,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy