Gatsby data updates require rebuild vs dynamic updates with Sanity Studio
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.
Recommended Approach
For most Sanity + Gatsby projects:
- Development: Use
watchMode: truefor instant preview - Production: Use webhooks to trigger rebuilds on content changes
- Optional: Add
overlayDrafts: trueto preview unpublished content during development
This gives you a great editing experience while maintaining the performance benefits of static sites!
Show original thread24 replies
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.