Issue with Gatsby watch mode not refreshing when referenced document is updated in Sanity CMS.
Based on the Sanity documentation I've reviewed, I cannot definitively confirm whether the behavior you're experiencing is expected or a bug. The gatsby-source-sanity documentation describes that watchMode enables real-time content preview by setting up a listener that pushes changes from Sanity to Gatsby, but it doesn't explicitly address how referenced documents should behave in this scenario.
What we know about gatsby-source-sanity:
The plugin is designed to be highly efficient, making only two API requests during the build process. When watchMode is enabled, it sets up a listener for real-time updates. However, the official documentation doesn't clarify whether changes to referenced documents should automatically trigger rebuilds of pages that reference them.
Your specific situation:
You're seeing Gatsby recompile when you edit a referenced document (visible in terminal), but the page doesn't reload with the changes until you edit the parent page document. This suggests the plugin is detecting the change but may not be triggering the full rebuild chain for documents that reference the changed content.
Potential approaches to investigate:
- Check your GraphQL queries: Make sure you're using
_rawContentfields withresolveReferenceswhen querying referenced documents:
query {
sanityPage {
_rawContent(resolveReferences: {maxDepth: 5})
}
}The _raw fields are specific to gatsby-source-sanity and designed to properly resolve references within your content.
Verify your token permissions: Ensure your
MY_SANITY_TOKENhas read permissions for all the document types (page, nav, section, footer).Check the gatsby-source-sanity GitHub issues: This might be a known issue or limitation with the plugin. I'd recommend searching the gatsby-source-sanity GitHub repository for similar issues or opening a new issue with your specific setup to get input from the maintainers.
Temporary workaround: As you've discovered, editing the parent document triggers the refresh. You could add a "Last Modified" timestamp field to your page document and update it when needed during development.
Without access to verified information about this specific behavior in the plugin's issue tracker or detailed documentation, I can't confirm if this is expected behavior or a bug. I'd recommend reaching out to the Sanity community on their Slack community or opening a GitHub issue with this specific scenario to get a definitive answer from the plugin maintainers who can confirm the intended behavior.
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.