Skip to content
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

Open
wants to merge 2 commits into
base: next
Choose a base branch
from

Conversation

bjoerge
Copy link
Member

@bjoerge bjoerge commented Aug 20, 2024

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 go

What 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

@bjoerge bjoerge requested a review from a team as a code owner August 20, 2024 15:07
@bjoerge bjoerge requested review from rexxars and removed request for a team August 20, 2024 15:07
Copy link

vercel bot commented Aug 20, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
page-building-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 27, 2024 9:50am
performance-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 27, 2024 9:50am
test-compiled-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 27, 2024 9:50am
test-next-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 27, 2024 9:50am
test-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 27, 2024 9:50am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
studio-workshop ⬜️ Ignored (Inspect) Visit Preview Aug 27, 2024 9:50am

Copy link
Contributor

No changes to documentation

Copy link
Contributor

github-actions bot commented Aug 20, 2024

Component Testing Report Updated Aug 27, 2024 9:55 AM (UTC)

❌ Failed Tests (1) -- expand for details
File Status Duration Passed Skipped Failed
comments/CommentInput.spec.tsx ✅ Passed (Inspect) 43s 15 0 0
formBuilder/ArrayInput.spec.tsx ✅ Passed (Inspect) 8s 3 0 0
formBuilder/inputs/PortableText/Annotations.spec.tsx ✅ Passed (Inspect) 30s 6 0 0
formBuilder/inputs/PortableText/copyPaste/CopyPaste.spec.tsx ✅ Passed (Inspect) 38s 11 7 0
formBuilder/inputs/PortableText/copyPaste/CopyPasteFields.spec.tsx ✅ Passed (Inspect) 0s 0 12 0
formBuilder/inputs/PortableText/Decorators.spec.tsx ✅ Passed (Inspect) 17s 6 0 0
formBuilder/inputs/PortableText/DisableFocusAndUnset.spec.tsx ✅ Passed (Inspect) 10s 3 0 0
formBuilder/inputs/PortableText/DragAndDrop.spec.tsx ✅ Passed (Inspect) 3m 0s 0 0 0
formBuilder/inputs/PortableText/FocusTracking.spec.tsx ✅ Passed (Inspect) 44s 15 0 0
formBuilder/inputs/PortableText/Input.spec.tsx ✅ Passed (Inspect) 1m 46s 21 0 0
formBuilder/inputs/PortableText/ObjectBlock.spec.tsx ✅ Passed (Inspect) 1m 15s 18 0 0
formBuilder/inputs/PortableText/PresenceCursors.spec.tsx ✅ Passed (Inspect) 9s 3 9 0
formBuilder/inputs/PortableText/RangeDecoration.spec.tsx ✅ Passed (Inspect) 25s 9 0 0
formBuilder/inputs/PortableText/Styles.spec.tsx ✅ Passed (Inspect) 18s 6 0 0
formBuilder/inputs/PortableText/Toolbar.spec.tsx ❌ Failed (Inspect) 1m 24s 20 0 1
formBuilder/tree-editing/TreeEditing.spec.tsx ✅ Passed (Inspect) 0s 0 3 0
formBuilder/tree-editing/TreeEditingNestedObjects.spec.tsx ✅ Passed (Inspect) 0s 0 3 0

Copy link
Member

@rexxars rexxars left a 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

@bjoerge
Copy link
Member Author

bjoerge commented Aug 27, 2024

should have tests unless it is only going to be used for PoC-type experiments

Good callout :)

Added tests in 2897248

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants