-
Notifications
You must be signed in to change notification settings - Fork 426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(preview): add experimental support for observing full documents #7397
base: next
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Skipped Deployment
|
No changes to documentation |
Component Testing Report Updated Aug 27, 2024 9:55 AM (UTC) ❌ Failed Tests (1) -- expand for details
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good, but should have tests unless it is only going to be used for PoC-type experiments
66bccc0
to
5887a68
Compare
5887a68
to
2897248
Compare
Good callout :) Added tests in 2897248 |
Description
In certain cases its useful to be able to subscribe to the complete version of a document (by id) and receive updates to it as it changes in the backend. The only way to achieve this in the Studio today involves either setting up a full optimistic mutation pipeline, or setting up a "live query", both of which adds a separate listener connection per document. This doesn't scale well, so this PR proposes an alternative approach that re-uses the global listener currently use for Studio previews.
The intended use is cases where you always need the latest version of a complete document, but don't need to be able to do optimistic updates to it (i.e. you can live with a server roundtrip).
It introduces two new method to the preview store API, both unstable and marked as internal for now:
unstable_observeDocument(id: string)
- returns an observable that will emit new versions of the document as it changes remotely.unstable_observeDocumentIds(ids: string[])
- thin convenience wrapper over the above that supports subscribing to multiple documents in one goWhat to review
The global query listener is now set up with
effectFormat=mendoza
which makes the mutation events include a (usually compact) patch that is used to patch the local version of the document as it receives remote changes. This will add a little bit of overhead and it might be worth considering adding this only if needed. That said, we did receive regular mutations over this listener up until recently, which tends to be much larger in size than mendoza patches.Testing
These methods are only used in a feature branch for now, we'll look into some automated tests for them as we start relying on them more.
Notes for release
n/a - internal for now