From aaa694da9b8928cda53125598159817c776b5e9c Mon Sep 17 00:00:00 2001 From: Henrik Wenz Date: Wed, 8 Aug 2018 15:13:20 +0200 Subject: [PATCH] Throw error if getInitialProps is defined as as instance method Omitting the static keyword happens pretty often. Therefore we should trigger a warning in devmode. Closes: #4782 --- lib/utils.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/utils.js b/lib/utils.js index 22faec6a62f2a..2474870175c41 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -54,6 +54,14 @@ export function isResSent (res) { } export async function loadGetInitialProps (Component, ctx) { + if (process.env.NODE_ENV !== 'production') { + if (Component.prototype && Component.prototype.getInitialProps) { + const compName = getDisplayName(Component) + const message = `"${compName}.getInitialProps()" is defined as an instance method.` + throw new Error(message) + } + } + if (!Component.getInitialProps) return {} const props = await Component.getInitialProps(ctx)