👀 Our most exciting product launch yet 🚀 Join us May 8th for Sanity Connect

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).
May 10, 2022, 9:33 PM
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.
May 10, 2022, 9:53 PM
Hi there
May 10, 2022, 10:12 PM
In our getStaticProps() call, if the preview argument is true then we flip the
useCdn
sanity client config value to false
May 10, 2022, 10:12 PM
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
May 10, 2022, 10:13 PM
the disconnect is trying to sort out, when the next preview cookie is set how is the old data still being pulled… 🤔
May 10, 2022, 10:14 PM
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
May 10, 2022, 10:14 PM
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.
May 10, 2022, 10:27 PM
Yeah that makes sense - it feels like the issue is related to being authenticated vs not
May 11, 2022, 12:13 AM
Thanks for the mindshare on this!
May 11, 2022, 12:13 AM
You're very welcome! Community support can be a joyous thing 😃
May 11, 2022, 12:23 AM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?