Skip to content

Commit

Permalink
Throw error if getInitialProps is defined as as instance method
Browse files Browse the repository at this point in the history
Omitting the static keyword happens pretty often. Therefore we should trigger a warning in devmode.

Closes: vercel#4782
  • Loading branch information
HaNdTriX committed Aug 9, 2018
1 parent 136585e commit aaa694d
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit aaa694d

Please sign in to comment.