Skip to content

Commit

Permalink
Warn if getInitialProps is defined as as instance method
Browse files Browse the repository at this point in the history
Ommitting the static keyword happens pretty often. Therefore we should warn the devloper in devmode.

Closes: vercel#4782
  • Loading branch information
HaNdTriX committed Aug 8, 2018
1 parent 9018da1 commit 0cfc658
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ export function isResSent (res) {
}

export async function loadGetInitialProps (Component, ctx) {
if (
process.env.NODE_ENV !== 'production' &&
Component.prototype &&
Component.prototype.getInitialProps
) {
const compName = getDisplayName(Component)
console.warn(`"${compName}.getInitialProps()" is not defined as a static method and therefor ommited.`)
}

if (!Component.getInitialProps) return {}

const props = await Component.getInitialProps(ctx)
Expand Down

0 comments on commit 0cfc658

Please sign in to comment.