Skip to content

perf(flow-chat): narrow live mailbox subscription to prevent unnecessary permission UI re-renders - #3828

Open
Raing5Days wants to merge 3 commits into
openBitFun:mainfrom
Raing5Days:perf/auto-opcase-auto-usepermissionrequests-01-1108-1941
Open

Raing5Days wants to merge 3 commits into
openBitFun:mainfrom
Raing5Days:perf/auto-opcase-auto-usepermissionrequests-01-1108-1941

Conversation

@Raing5Days

@Raing5Days Raing5Days commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Problem

In usePermissionRequests, the hook previously subscribed to the whole liveSessionInteractionStore snapshot via a coarse useSyncExternalStore:

const liveMailbox = useSyncExternalStore(
  liveSessionInteractionStore.subscribe,
  liveSessionInteractionStore.getActiveSnapshot,
  liveSessionInteractionStore.getActiveSnapshot,
);

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.is comparison failed on every store publication. This forced usePermissionRequests consumers to repeatedly re-render and recompute permission projections even when surfaceId and requests were completely unchanged.

Solution

Narrowed the external store subscriptions into two focused, zero-argument slice projections:

  • getLiveSurfaceId: extracts only surfaceId.
  • getLiveRequests: extracts only requests.

Both slices are derived directly from the store's immutable state and subscribed independently via useSyncExternalStore. React now bails out re-renders via Object.is whenever unrelated mailbox fields update, while strictly preserving snapshot immutability (no in-place mutations or fragile ad-hoc caches).

Verification

  • Unit tests: pnpm --filter @openbitfun/web-ui test -- usePermissionRequests (7/7 tests passed).
  • Repository hygiene: node scripts/check-repo-hygiene.mjs passed.
  • Reference stability: Microbenchmarks confirm 100% reference stability on unaffected cycles without missed UI updates.

@Raing5Days
Raing5Days force-pushed the perf/auto-opcase-auto-usepermissionrequests-01-1108-1941 branch from a9f8f56 to df9ca67 Compare November 8, 2026 11:45
@Raing5Days Raing5Days changed the title perf(state-architecture): autonomous optimization for OpCase-Auto-Usepermissionrequests-01 perf(flow-chat): narrow live mailbox subscription to prevent unnecessary permission UI re-renders Nov 8, 2026
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.

1 participant