-
Notifications
You must be signed in to change notification settings - Fork 435
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
fix(core): avoid unnecessary re-renders in useDocumentPresence #7365
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 22, 2024 5:07 PM (UTC) ❌ Failed Tests (1) -- expand for details
|
) | ||
.filter((item) => debugIntrospect || item.presence.sessionId !== SESSION_ID), | ||
), | ||
shareReplay(1), |
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.
I suppose we can eliminate shareReplay
this as its introducing new behavior. Thought was that new subscribers could get the latest event sent to them when they subscribe.
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.
Good call! allSessions$
already replays it's latest value to new subscribers, but this also shares the mapping work done above between all subscribers 👌🏼
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, thanks a lot @runeb!
) | ||
.filter((item) => debugIntrospect || item.presence.sessionId !== SESSION_ID), | ||
), | ||
shareReplay(1), |
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.
Good call! allSessions$
already replays it's latest value to new subscribers, but this also shares the mapping work done above between all subscribers 👌🏼
* fix(core): avoid unnecessary re-renders in useDocumentPresence * fix(core): make sure useDocumentPresence only emits when there are changes
Description
When presence store receives announcements, consumers of
useDocumentPresence
receive subscription updates that relate to thedocumentId
they are interested in. This patch fixes a bug where the store would continually emit[]
to all subscribers that did not have any presence state, which due tosetState
caused them to re-render.The first fix for this was to leverage
useReducer
inuseDocumentPresence
to only cause a re-render when the presence data actually changed, but in a second commit I have attempted to fix this in the presence store itself, making sure to only emit if there are changes. This means we will emit[]
when first subscribed, but from then only when there is an update to presence data for the givendocumentId
.What to review
The split between common subscription data and
documentId
specific data, the usage ofshareReplay
and the equality checks.Testing
I can confirm that this reduces the amount of re-renders happening in the Studio, since each
PaneItem
now only re-renders when presence data relating to theirdocumentId
has changed.Notes for release
Optimized rendering of changes in presence