-
Notifications
You must be signed in to change notification settings - Fork 421
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
refactor(preview): extract global listener, refactor preview APIs and improve typings #7360
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 19, 2024 3:27 PM (UTC) ✅ All Tests Passed -- expand for details
|
'*[!(_id in path("_.**"))]', | ||
{}, | ||
{ | ||
events: ['welcome', 'mutation', 'reconnect'], |
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.
reconnect
is filtered out downstream for now, but we might want to consider using this at a later point
|
||
// This will keep the listener active forever and in turn reduce the number of initial fetches | ||
// as less 'welcome' events will be emitted. | ||
// @todo: see if we can delay unsubscribing or connect with some globally defined shared listener |
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.
// @todo: see if we can delay unsubscribing or connect with some globally defined shared listener
^ This has been addressed in this PR
*/ | ||
export function createObserveFields(options: { | ||
client: SanityClient | ||
invalidationChannel: Observable<InvalidationChannelEvent> |
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.
named it invalidationChannel
and stripped down types to make it clear that it's merely used to notify about need for refetching preview queries
43e817e
to
1ae5e37
Compare
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.
This looks good to me :)
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.
Looks great! I'd like to start marking anything exported (from any file, regardless of whether or not it is "public") with visibility modifiers (eg @internal
) since it makes it easier to reason about how scary it is to change - but not a blocker.
…PIs and improve typings
Co-authored-by: Espen Hovlandsdal <espen@hovlandsdal.com>
0c3a194
to
3c8cba7
Compare
Did a rebase, and looks like a new approval is required |
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.
🚀
… improve typings (#7360) * refactor(preview): extract global listener, refactor preview APIs and improve typings * fixup! refactor(preview): extract global listener, refactor preview APIs and improve typings * Apply suggestions from code review Co-authored-by: Espen Hovlandsdal <espen@hovlandsdal.com> --------- Co-authored-by: Espen Hovlandsdal <espen@hovlandsdal.com>
Description
Note: This originally happened as part of work in a feature branch, but the changes here are generic and standalone improvements that makes sense to merge to main already.
This extracts the global listener used by the preview system, improves consistency and readability and typings of of the core/preview code. These changes should not affect the behavior of previews in any significant way or cause any visible differences in how previews work currently.
This also includes a small improvement to the global preview listener: Currently this listener is subscribed once, and the subscription is kept active forever. This means that if the user navigates to a part of the Studio that does need to preview anything, the listener connection is still kept active. With the changes proposed here, the global preview listener is now refcount'ed, and shuts down when no longer needed. To avoid excessive unsubscribe+resubscribes, the listener teardown is delayed to two seconds after the last subscriber unsubscribes. Demo here:
Screen.Recording.2024-08-12.at.18.33.33.mov
What to review
Does the changes make sense?
Testing
Existing tests should be enough. Also improves TypeScript coverage, which helps.
Notes for release
n/a - not user facing