Next.js Preview Mode Showing Old Content

10 replies
Last updated: May 11, 2022
Howdy, has anyone run into this with next.js? We are using next.js preview mode which is working nicely with sanity. However, i’ve noticed if we try and view a preview page in a different browser or incognito’d window, preview mode is being activated (we see the cookie being set by next) but we are seeing the older “published” content, not the updated content in sanity (that hasn’t been published yet).
Is the Preview mode using the useCdn option in your Sanity config? I ran into something similar recently for unstable_revalidate and webhooks; it was sending things right away, but because the APICDN hadn't "flushed" yet, it immediately sent stale things.
When the config available to getStaticProps was false, the triggered updates were always fresh.
Hi there
In our getStaticProps() call, if the preview argument is true then we flip the
useCdn
sanity client config value to false
What’s odd is all of the preview stuff works as expected in the iframe preview, and if you open a the api/preview path in the same browser
the disconnect is trying to sort out, when the next preview cookie is set how is the old data still being pulled… 🤔
and yes to your point above, we had the same issue too and had to disable the CDN for previews exactly as you mentioned above
Is the preview client config using withCredentials? Makes me wonder if it's a draft being previewed and the incognito and other browser have cookies set but unauthenticated; if the docs say that logged-in people would see things properly in that scenario that would explain the iframe / same browser success and incognito / other-browser failure. I think, speculating, the "old data" is simply falling back to the published contents that preceded the draft rather than give unauthenticated people access to protected in-progress Studio data.
Yeah that makes sense - it feels like the issue is related to being authenticated vs not
Thanks for the mindshare on this!
You're very welcome! Community support can be a joyous thing 😃

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?