Sanity Studio changes not updating on deployed Vercel staging site

5 replies
Last updated: Sep 29, 2021
Hi, I'm working on a sanity project whose previous developer that started the project is no longer here. Meaning there are a few gaps of sanity knowledge that are missing on my end. Maybe someone can help with this:

THE ISSUE - Content changed on Sanity studio doesn't update on our deployed staging site. The only time changes occur if I manually have to make a manual push to our git repo which builds the vercel hosted site.

THE CURRENT BEHAVIOR• When updating things locally, everything works out fine. So the studio hosted on
localhost:3333
applies the changes to the site running on
localhost:3000
.• Funny enough, if I have my
localhost:3000
site running and update something on our organization's sanity studio ... those changes are reflected immediately on my localhost site 🤔• Any changes made on our organization's sanity studio do not get reflected on the staging site.

Note: The project I'm working on is made with Next.js X Sanity. It is initially bootstrapped from the Sanity/Next eCommerce Starter


If I could get any lead on where to start looking to align the CMS changes to our site, it would be great. Thanks 🙏
AI Update

Based on your description, this is a classic caching issue with Next.js and Sanity. The reason your localhost sees updates immediately while your staging site doesn't is because of how Next.js handles data fetching in development vs. production.

What's happening

In development (localhost:3000): Next.js fetches fresh data from Sanity on every page request, which is why you see changes immediately whether you update content locally or from your organization's hosted studio.

In production (your staging site): Next.js serves cached/pre-built pages and doesn't automatically know when content in Sanity has changed. That's why you only see updates after manually pushing code and triggering a new build.

The solution

You need to implement one of these approaches to tell your Next.js site when to refresh content:

The modern approach is using Sanity Functions to trigger Next.js revalidation when content changes. This is better than webhooks because it's native to Sanity and doesn't require external hosting.

Create a Sanity Function that calls your Next.js revalidation endpoint when documents change. Then create an API route in Next.js like:

// pages/api/revalidate.js (or app/api/revalidate/route.js for App Router)
export default async function handler(req, res) {
  // Validate the request (check for secret token)
  if (req.query.secret !== process.env.REVALIDATE_SECRET) {
    return res.status(401).json({ message: 'Invalid token' })
  }

  try {
    await res.revalidate('/') // Revalidate homepage
    await res.revalidate('/products') // Revalidate specific paths
    // Add more paths as needed
    return res.json({ revalidated: true })
  } catch (err) {
    return res.status(500).send('Error revalidating')
  }
}

2. Time-Based ISR (Simpler but less immediate)

Add a revalidate value to your data fetching. For the ISR (Incremental Static Regeneration) approach, if you're using the Pages Router:

export async function getStaticProps() {
  const data = await client.fetch(query)
  
  return {
    props: { data },
    revalidate: 60 // Regenerate page every 60 seconds
  }
}

Or in App Router with the newer sanityFetch:

const posts = await sanityFetch({
  query: POSTS_QUERY,
  revalidate: 60 // Check for updates every 60 seconds
})

3. Important: Disable Sanity's CDN for ISR

When using ISR, set useCdn: false in your Sanity client configuration. The Sanity CDN can interfere with ISR by serving cached data even when Next.js tries to revalidate:

const client = createClient({
  projectId: 'your-project-id',
  dataset: 'production',
  useCdn: false, // Disable CDN for ISR
  apiVersion: '2024-01-01',
})

Quick diagnostic

Check your existing code for:

  • Any getStaticProps functions - do they have a revalidate property?
  • Your Sanity client config - is useCdn set to true?
  • Any API routes in /pages/api/ or /app/api/ that handle revalidation
  • Webhook configurations in your Sanity project settings

Since this is based on the Next.js eCommerce starter, it likely uses static generation but may not have revalidation configured. The quickest fix is adding time-based ISR with revalidate, though on-demand revalidation with Sanity Functions gives you instant updates when content changes.

Show original thread
5 replies
Hi User, from the way you describe the issue it sounds like your Nextjs frontend is being deployed statically, and only get updated when you manually trigger deploy.
You can fix it by creating a new webhook for your staging site on vercel (see vercel docs for more info), then add it to your sanity project, either via the UI at
sanity.io/teams or via the command line.
NextJS when run locally will act as a single page app, meaning everytime you update data in the studio (deployed or local), it will refetch the data every refresh. You’re probably using the same dataset, that’s why changes in the deployed studio reflected immediately in local site.

Alternatively, if possible you can change the way you deploy your NextJS app so that data get updated automatically without re-deploying the site everytime. Please note that there are trade off, depending on your site’s traffic & size you may see increase or decrease api call / bandwidth usage
https://nextjs.org/docs/basic-features/data-fetching#incremental-static-regeneration
You can also install this plugin for manually trigger a rebuild that brings in the new content https://www.sanity.io/plugins/vercel-deploy
Or wait for our new webhooks to launch and automate it!
Thanks to both of you! I'll look into these
user Y
When are the new webhooks planned for?
Very soon 🙂

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?