for the sanity package, how would you fetch live data in nextjs preview mode?
You can override global context provider props like so
https://docs.plasmic.app/learn/global-contexts/#prop-override
The sanity fetcher package I believe has a global context provider that takes in a prop indicating whether it is supposed to fetch the latest draft/preview data or not, and you can set this conditionally based on whether you are in next JS preview mode
Let me know if that makes sense!
hi thanks for your reply. It makes total sense, but i can’t find that prop. The only one available is useCDN, but this one won’t fetch live data if set to false
I’m not super familiar with the sanity API myself, but I believe that from looking at the docs there is an auth token that you can pass, which normally you don’t need to set, but if you optionally override that argument in the context provider, then it should give you access to the draft documents like so
https://www.sanity.io/schemas/query-for-new-unpublished-documents-cde233fc
Here also is the full source for how exactly the sanity fetcher works
https://github.com/plasmicapp/plasmic/blob/master/plasmicpkgs/plasmic-sanity-io/src/sanity.tsx#L38
thanks for your reply yang. Setting the auth token does indeed allow to fetch draft documents from sanity. However, it does not fetch the live data so i always need to re-load to see the recent changes.
I am used to setting up a workflow where my team can see the changes live on the website like this (https://www.sanity.io/guides/nextjs-live-preview).
Is there a way we can ask the team that developed the sanity integration if this is possible? I know you guys have your own CMS now, but it is not yet as mature for complex CMS
One thing you can do to refresh your sanity data preview from within plasmic studio is, in the View menu, there’s a menu item for refresh data. That will reload the sanity data without refreshing the whole page/studio.
For making it possible to preview as you type on your published website, that would be neat! Filed the feedback with the team
That would be awesome, to be able to see changes live on our preview environment - not necessarily within the studio.
A simpler way would be to allow us to override the data in the sanity fetcher component. Not mega clean, but at least it could work with a relatively simple setup.