Unexpected behavior when getServerSideProps is defined but is set to undefined
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 142k
- Forks
- 32.5k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 334
Description
Run next info (available from version 12.0.8 and up)
No response
What version of Next.js are you using?
12.0.7
What version of Node.js are you using?
16.3.0
What browser are you using?
Firefox
What operating system are you using?
macOS
How are you deploying your application?
next start
Describe the Bug
When getServerSideProps is defined but is set to undefined next returns html on data request. Undefined is obviously invalid value but it is easy to happen if the page uses for example a higher-order function to wrap the getServerSideProps and it can be very confusing to find the cause.
Expected Behavior
Next should return either the json data or throw error or warning that getServerSideProps is not valid.
To Reproduce
// index.js
const Page = () => {
return <div>
<Link href="/page"><a>Page</a></Link>
</div>;
}
export default Page;
// page.js
export const getServerSideProps = undefined;
const Page = () => {
return <div>
page
</div>;
}
export default Page;
If user clicks on the link, next tries to fetch data and /_next/data/development/page.json returns html.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the index.js and page.js reproduction, then inspect handling of the /_next/data/development/page.json request when getServerSideProps is undefined. Confirm the behavior with next start on Next.js 12.0.7; done means the request returns valid JSON or a clear validation error rather than HTML.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nextjs
- Domain
- backend, web-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100