Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

21 changes: 21 additions & 0 deletions errors/invalid-getserversideprops-return-value.md
@@ -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)
4 changes: 4 additions & 0 deletions errors/manifest.json
Expand Up @@ -645,6 +645,10 @@
{
"title": "import-next",
"path": "/errors/import-next.md"
},
{
"title": "invalid-getserversideprops-return-value",
"path": "/errors/invalid-getserversideprops-return-value.md"
}
]
}
Expand Down
9 changes: 7 additions & 2 deletions packages/next/server/render.tsx
Expand Up @@ -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}`
)
}

Expand Down