Trouble with preview mode in Next.js

I have Preview mode set up in a Next.js as per the Prismic example.

So far as I can tell, I have everything configured correctly and yet Next.js will only load dynamic routes in preview mode on the first request of that page. After the page has been requested outside of Preview mode, it's no longer possible to view the page in preview mode again.

1. From the Prismic Editor UI, the user clicks on the Preview button which redirects to

https://myapp.prismic.io/previews/session/draft?previewId=X65pGRMAACEAEC0d&document=X7zhlRIAACIAz2iO&version=X85fixAAACQAOrMN`

2. Prismic then redirects to

https://my.actual.app/api/preview?token=https%3A%2F%2Filo-voices.prismic.io%2Fpreviews%2FX8IC3RAAACQAA0pG%3AX85fixAAACQAOrMN%3FwebsitePreviewId%3DX65pGRMAACEAEC0d&documentId=X7zhlRIAACIAz2iO

3. The api/preview endpoint then gets the redirectUrl from Prismic and redirects to /redirectUrl, setting the Next.js preview cookies.

set-cookie: __prerender_bypass=391b9dd5be2db3f82d091836f424ccd3; Path=/; HttpOnly; Secure; SameSite=None

set-cookie: __next_preview_data=eyJhbGciOiJIUzI1NiIsInR5c...; Path=/; HttpOnly; Secure; SameSite=None

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 getStaticProps getting called.

I thought this might be an issue with getStaticProps in Next.js and opened up this issue a few days ago.

Any help with this would be hugely appreciated!

Did some digging and think this results from aggressive caching in Next.js. Opened this issue which should hopefully fix it.

2 Likes

Figured it out. Solution here for anyone who runs into a similar situation: https://github.com/vercel/next.js/issues/19714#issuecomment-740699384

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.