[Preview] Setting preview cookies doesn't bypass static generation #19944
Replies: 1 comment
|
The behavior described here does look abnormal. In Next.js, Preview Mode is specifically designed to bypass the statically generated version of a page. When the preview cookies are valid, the request should cause Since the issue only appears after leaving Preview Mode and then trying to enter it again, I would investigate the following areas:
The fact that rebuilding the application makes Preview Mode work again is particularly interesting. It suggests that the rebuild may be resetting some state related to static generation or caching, rather than actually fixing the Preview Mode cookies themselves. My preferred way to debug this would be to completely isolate Prismic first:
If the problem can be reproduced with this minimal setup, then I would investigate Next.js and the deployment/cache layer. If the minimal example works correctly, then I would focus on the Prismic integration, redirects, or caching behavior. Also, because this GitHub discussion dates back to December 2020, I would be careful about applying its workaround directly to a modern Next.js application. The rendering and caching architecture of Next.js has changed significantly since then. |
Uh oh!
There was an error while loading. Please reload this page.
I opened an issue for this as a bug #19714 , which I'm pretty sure is correct, but I'm sharing it here as well in case someone has ever encountered this situation before and found a work around.
tl;dr I can't get Preview Mode to work in production because
getStaticPropsnever gets called even though the preview cookies are set. Here's a synopsis (I'm doing this with Prismic CMS)1. From the Prismic Editor UI, the user clicks on the Preview button which redirects to
2. Prismic then redirects to
3. The
api/previewendpoint then gets theredirectUrlfrom Prismic and redirects to/redirectUrl, setting the Next.js preview cookies.I am able to load the page in preview mode immediately after deploying and rebuilding the app to the server (Digital Ocean App Platform). However, if I leave Preview mode and load the page again, I am no longer able to view it in Preview Mode afterwards. Successive attempts redirect me to the correct page with the cookies set, but without
getStaticPropsgetting called.On localhost, bizarrely, it works fine on FireFox but not at all on Chrome.
Any help with this would be hugely appreciated!
All reactions