question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Preview Mode has getServerSideProps({ preview, previewData }) in dev builds, not production builds.

See original GitHub issue

Bug 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.

  1. 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.
  2. Start server in development mode
  3. Hit your /api/preview endpoint.
  4. Observe preview and previewData are present on your test page, as well as the preview mode cookies.
  5. Clear your cookies.
  6. Stop the server
  7. Build for production.
  8. Start the server in production mode
  9. Hit your /api/preview endpoint again to start preview mode again.
  10. 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:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
sathovsepyancommented, Nov 6, 2020

Hi @xiata. Did you find any solution for this? I’m facing the same problem.

0reactions
balazsorban44commented, Jan 27, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found