Update: Add appropriate error message when for getServerSideProps invalid return value (#35887)
This commit is contained in:
parent
07723be8b3
commit
cb565d69cf
3 changed files with 32 additions and 2 deletions
21
errors/invalid-getserversideprops-return-value.md
Normal file
21
errors/invalid-getserversideprops-return-value.md
Normal 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)
|
|
@ -645,6 +645,10 @@
|
|||
{
|
||||
"title": "import-next",
|
||||
"path": "/errors/import-next.md"
|
||||
},
|
||||
{
|
||||
"title": "invalid-getserversideprops-return-value",
|
||||
"path": "/errors/invalid-getserversideprops-return-value.md"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -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}`
|
||||
)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue