-
Notifications
You must be signed in to change notification settings - Fork 501
Open
Description
As part of the addition of the live events API, the SanityClient.fetch method returns syncTags which can be used to cache fetch requests. The fetch request cache can then be selectively invalidated based on events emitted by the Live Content API, but there is no way outside of that API to determine the correct tags to invalidate.
I would like to be able to selectively invalidate the fetch request cache via Sanity webhook. Possible approaches that come to mind are:
- Adding a GROQ delta function which calculates the
syncTagsbased on the changes to the document, which could then be used in a document webhook projection, or - Adding an additional type of webhook which triggers on any document create/update/delete and returns only the applicable
syncTags.
As an alternative I have looked at Live Content API based invalidation via the defineLive function provided by next-sanity/live, but:
- Fetch cache invalidation is integrated with other functionality which provides live updates to content on the page. This is undesirable in my case due to layout shift and I would therefore prefer to avoid using the live content API at all rather than using the workaround suggested in
next-sanityof wrapping the rendering of all data in auseDeferredLayoutShifthook. - The fetch cache is only invalidated if an active user is on the site. The initial connection created by
next-sanity/livedoes not send thelast-event-idheader so any changes made in the studio when there is no active user are never processed, leading to outdated content. I considered the two workarounds suggested innext-sanitybut as noted the first workaround is a "heavy hammer" and the second workaround requires running a separate long-running server to forward live events to a Next.js route (essentially a webhook with extra steps).
Metadata
Metadata
Assignees
Labels
No labels