Repository navigation
perf(flow-chat): narrow live mailbox subscription to prevent unnecessary permission UI re-renders - #3828
Open
Raing5Days wants to merge 3 commits into
Conversation
…permissionrequests-01
Raing5Days
force-pushed
the
perf/auto-opcase-auto-usepermissionrequests-01-1108-1941
branch
from
November 8, 2026 11:45
a9f8f56 to
df9ca67
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In
usePermissionRequests, the hook previously subscribed to the wholeliveSessionInteractionStoresnapshot via a coarseuseSyncExternalStore:Because
liveSessionInteractionStore.getActiveSnapshot()yields a new object whenever any unrelated mailbox field churns (such as draft text updates, reading anchor movements, or resolution flags in other sessions),Object.iscomparison failed on every store publication. This forcedusePermissionRequestsconsumers to repeatedly re-render and recompute permission projections even whensurfaceIdandrequestswere completely unchanged.Solution
Narrowed the external store subscriptions into two focused, zero-argument slice projections:
getLiveSurfaceId: extracts onlysurfaceId.getLiveRequests: extracts onlyrequests.Both slices are derived directly from the store's immutable state and subscribed independently via
useSyncExternalStore. React now bails out re-renders viaObject.iswhenever unrelated mailbox fields update, while strictly preserving snapshot immutability (no in-place mutations or fragile ad-hoc caches).Verification
pnpm --filter @openbitfun/web-ui test -- usePermissionRequests(7/7 tests passed).node scripts/check-repo-hygiene.mjspassed.