gatsby-source-sanity
gatsby-source-sanity copied to clipboard
Watch Mode does not refresh when a referenced document is updated in the studio
If you update a document watchmode notices the change.The change doesn't occur on documents referencing the changed document.
However, If you make any other minor edit to the document referencing the original document, the changes to the original document are noticed.
Heres a few Slack Conversations outlining this issue:
https://sanity-io-land.slack.com/archives/C9Z7RC3V1/p1621279143160000
https://sanity-io-land.slack.com/archives/C9Z7RC3V1/p1621374667081200
This occurs whether you reference the document directly in the schema or if you use an object that references the document indirectly. This is a pattern I tried based on one of the examples in the sanity-kitchen-sink starter.
We've also attempted to place the reference to the document within block content. The results are the same.
export default {
title: "Page Block Content",
name: "pageBlockContent",
type: "array",
of: [
{
title: "Block",
type: "block",
styles: [
{ title: "H1", value: "h1" },
{ title: "H2", value: "h2" },
],
},
{
name: 'section',
title: 'Section Content',
type: 'reference',
to: [{type: 'section'}]
}
],
};
One thing I've noticed is that the prop data is not being updated when changes to reference documents are made.
To reproduce.
- Set up a schema with a document referencing another document as described above.
- Open react dev tools, find the target component and inspect the props.
- From the sanity studio / cms update one of the referenced documents.
The expected behavior is that the props data changes and the page re-renders. Actual behavior is that the props data does not change and there's no re-render.
If you make any change to the parent document, the prop data does change, the page re-renders and the new data is displayed.
Interestingly if you have nested documents, changing the top level parent document cascades all of the updates to the props. For example.
Page Document references a Section Document which references a ContentBlock document. If you change the Content Block document, no data up date to props or re-render occurs. If you then make a change to the top level Page Document, the props are updated and the re-render does occur.
Is this actually the expected behavior or a bug?
Here's a quick video showing what I encountered:
https://vimeo.com/3200pro/review/553041014/a5a8eb1ce3
** Working through it with a colleague he noticed that adding a direct query to the document referenced caused the auto-update to happen. This isn't a fix but a temporary workaround for now.
allReferencedDocumentName {
edges {
node {
id
}
}
}
No other information is even needed in the query above to allow for the updates.
Here's a detailed Q&A that I posted on StackOverflow
https://stackoverflow.com/questions/67577112/how-do-i-get-watch-mode-with-sanity-io-and-gatsby-to-refresh-content-when-refere/67641620#67641620