Update: Add appropriate error message when for getServerSideProps invalid return value (#35887)

This commit is contained in:
Samuel 2022-04-06 17:25:27 +02:00 committed by GitHub
parent 07723be8b3
commit cb565d69cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 2 deletions

View file

@ -0,0 +1,21 @@
# Invalid getServerSideProps Return Value
#### Why This Error Occurred
In one of the page's `getServerSideProps` the return value had the incorrect shape.
#### Possible Ways to Fix It
Make sure to return the following shape from `getServerSideProps`:
```ts
export async function getServerSideProps(ctx: GetServerSidePropsContext) {
return {
props: { [key: string]: any }
}
}
```
### Useful Links
- [getServerSideProps](https://nextjs.org/docs/api-reference/data-fetching/get-server-side-props)

View file

@ -645,6 +645,10 @@
{
"title": "import-next",
"path": "/errors/import-next.md"
},
{
"title": "invalid-getserversideprops-return-value",
"path": "/errors/invalid-getserversideprops-return-value.md"
}
]
}

View file

@ -255,12 +255,17 @@ export type RenderOptsPartial = {
export type RenderOpts = LoadComponentsReturnType & RenderOptsPartial
const invalidKeysMsg = (methodName: string, invalidKeys: string[]) => {
const invalidKeysMsg = (
methodName: 'getServerSideProps' | 'getStaticProps',
invalidKeys: string[]
) => {
const docsPathname = `invalid-${methodName.toLocaleLowerCase()}-value`
return (
`Additional keys were returned from \`${methodName}\`. Properties intended for your component must be nested under the \`props\` key, e.g.:` +
`\n\n\treturn { props: { title: 'My Title', content: '...' } }` +
`\n\nKeys that need to be moved: ${invalidKeys.join(', ')}.` +
`\nRead more: https://nextjs.org/docs/messages/invalid-getstaticprops-value`
`\nRead more: https://nextjs.org/docs/messages/${docsPathname}`
)
}