Preview Mode has getServerSideProps({ preview, previewData }) in dev builds, not production builds.
See original GitHub issueBug report
Describe the bug
Preview Mode does not work correctly in production.
In development mode, /[…slug].js endpoint’s getServerSideProps(props)
receives props preview
and previewData
as mentioned by documentation.
In production mode, /[…slug].js endpoint’s getServerSideProps(props)
does not receive those props, despite __next_preview_data
and __prerender_bypass
cookies present in the request.
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
Setup preview mode per docs.
- Build /[…slug].js endpoint that uses getServerSideProps({ params, preview, previewData }). This page should send preview and previewData as props to be rendered so you can see it working or not.
- Start server in development mode
- Hit your /api/preview endpoint.
- Observe preview and previewData are present on your test page, as well as the preview mode cookies.
- Clear your cookies.
- Stop the server
- Build for production.
- Start the server in production mode
- Hit your /api/preview endpoint again to start preview mode again.
- Observe preview and previewData are NOT present on your test page, but the cookies are present.
Expected behavior
Development and production mode to actually behave the same instead of being completely broken in production builds.
System information
- OS: macOS 10.15.7
- Browser: Chrome stable
- Version of Next.js: 9.5.5
- Version of Node.js: 12.18.4
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Advanced Features: Preview Mode | Next.js
First, create a preview API route. It can have any name - e.g. pages/api/preview.js (or .ts if using TypeScript). In this API route,...
Read more >How the new Next.js 9.3 Preview Mode works and why it's a ...
Because getStaticProps runs at build time, it does not receive data that's only available during request time, such as query parameters or HTTP ......
Read more >getServerSideProps working fine in dev mode but fails in ...
I'm getting my data properly when I'm in dev mode but as soon as I deployed it to production using vercel I was...
Read more >What is Next.js getInitialProps and getServerSideProps? | refine
Next.js is an open-source React framework for building production ... Returns true if the page utilizes Preview Mode and false otherwise.
Read more >Enabling Preview mode in your Next.js application - Enterspeed
Creating a Preview API route. Next.js provides a solution to build your API. This is done by creating a folder called api inside...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @xiata. Did you find any solution for this? I’m facing the same problem.
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.