Gatsby data updates require rebuild vs dynamic updates with Sanity Studio

24 replies
Last updated: Nov 30, 2020
Hello!
Recently started to play with sanity and gatsby.js for a new project I want to work on. On your site I noticed that you have a few templates up with next.js and gatsby for ecommerce/blog sites. I set up the gatsby template and deployed it and everything but I can seem to understand why when I update data in the Studio, the only way to update data on the front-end is to redeploy. Is this supposed to be happening? Or should it update dynamically. I know its using SSR but I thought that there would be some sort of "incremental static regeneration".

Sorry if this is a bad question, I'm just really having trouble understanding.
AI Update

Great question! This is a common point of confusion when starting with Gatsby and Sanity. What you're experiencing is expected behavior for a static site generator like Gatsby, but there are several ways to get more dynamic updates.

Why You Need to Redeploy

Gatsby generates static HTML files at build time (SSG - Static Site Generation). When you run gatsby build, it fetches all your content from Sanity and creates static pages. Once built, those pages don't automatically know about content changes in Sanity - that's why you need to rebuild to see updates.

This is different from Next.js's Incremental Static Regeneration (ISR), which can automatically rebuild pages on-demand. Gatsby doesn't have true ISR in the same way, though it does support incremental builds.

Solutions for Dynamic Updates

1. Development Mode with watchMode (Instant Updates)

During development, you can see changes in real-time! The gatsby-source-sanity plugin supports watchMode which pushes changes from Sanity to Gatsby instantly:

// gatsby-config.js
{
  resolve: 'gatsby-source-sanity',
  options: {
    projectId: 'your-project-id',
    dataset: 'production',
    watchMode: true, // Enable real-time updates in dev
    overlayDrafts: true, // See draft content
    token: process.env.SANITY_TOKEN // Required for drafts
  }
}

When you run gatsby develop, changes in Sanity Studio will appear immediately without restarting.

2. Webhooks + Automated Rebuilds (Production)

For production, set up webhooks to trigger automatic rebuilds when content changes:

  • Create a build hook in your hosting platform (Netlify, Vercel, etc.)
  • Configure a Sanity webhook to call that build hook when documents change
  • Your site rebuilds automatically (usually takes 1-5 minutes)

3. Gatsby Cloud Incremental Builds

If you host on Gatsby Cloud, it supports incremental builds that only rebuild changed pages, making updates much faster than full rebuilds.

4. Gatsby Server-Side Rendering (SSR)

For pages that need real-time data, Gatsby 4+ supports SSR using getServerData. These pages fetch fresh data on every request, but this requires server hosting (not static hosting).

What About DSG?

Gatsby also has Deferred Static Generation (DSG) which generates pages on-first-request, but once generated, they're still static until the next build.

For most Sanity + Gatsby projects:

  • Development: Use watchMode: true for instant preview
  • Production: Use webhooks to trigger rebuilds on content changes
  • Optional: Add overlayDrafts: true to preview unpublished content during development

This gives you a great editing experience while maintaining the performance benefits of static sites!

Show original thread
24 replies
I think you’re asking why it doesn’t build automatically when you update content? In that case, you need to set it up to trigger a build when you publish content in the studio. It’s in manage.sanity.io in settings > API > Add new webhook, you get the webhook from Netlify and copy/paste it there.
If that’s not what you mean then disregard
Yes, thank you for the response! I managed to add the webhook to the API settings, but it still doesn't trigger a new build when I publish something new.
You’re publishing from the actual studio, not a local server setup? And you grabbed the webhook from the Gatsby frontend, not the studio?
It’s the frontend that needs to re-build for the changes to display
Yeah, I was getting the hook from netlify, for some reason it keeps rebuilding the studio and not the front-end
and yes--not local server
Are you sure you set up the webhook on the Gatsby build? I haven’t used the Gatsby starter, I use 11ty, but if I’m not mistaken they both deploy two Netlify builds one for the frontend one for the studio. It sounds like maybe you set up the webhook on the studio build? If that’s not it I’m not sure
Yeah--I got it to work , it was my fault, grabbed the wrong webhook
however, it still takes forever to rebuild
I did exactly the same thing when I set mine up for the first time. 😂
😂
It does that when it’s waiting for another build to finish
got it, yeah is it supposed to take a while to re-deploy? or is there any way to get quicker updates through this approach?
There are different things you can do to minimize build time, but in general it’s going to take a couple minutes for smaller sites. I’ve heard of larger sites taking quite a lot of time to build.
Once your site scales to the point where build time is a real issue, you can split it into smaller micro-sites so that only the parts you update are re-built (for instance, separating a site’s blog and store). Netlify’s free tier is 300 build minutes per month, I’ve yet to exceed that running two smaller sites
ah okay, makes sense. my usecase is an eCommerce website, but taking into consideration, every time an item is bought it would have to redeploy to update quantity on an item?
I don't think waiting for it to rebuild for 2 minutes will work, unless I'm thinking of it completely wrong.
I haven’t yet built an eCommerce app with jamstack so I’m not 100% sure how it works, but I think that’s handled by whichever API is running your store. Again I’m not 100%, don’t want to give you bad info
Got it, no problem. I appreciate your help otherwise!
Of course! This slack channel has helped me a whole lot so I try to pay it forward whenever possible. 😁
Re: build time, you might want to check into Gatsby Cloud and incremental builds (can also make it work on Netlify). https://www.netlify.com/blog/2020/04/23/enable-gatsby-incremental-builds-on-netlify/
Also, check if the build script clears the cache and that you also check in package-lock files so it doesn't need to reinstall all that stuff everytime.
Some data is simply too dynamic, and it no longer makes sense to generate static sites for it. "Items left in stock" is probably a good example (unless you stock something that sells very rarely..)
You should probably go for an API-type solution
🙂
You may want to watch how Prima.co was made: https://www.youtube.com/watch?v=_Vc08kO7qmQ

user G
goes over a fair amount of details on how it was put together and the considerations needed.
Awesome, thank you all for the replies! I really appreciate it.

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?