Extract thread grouping logic and add stable wrapper identity - #3937
Draft
adamleithp wants to merge 2 commits into
Draft
Extract thread grouping logic and add stable wrapper identity#3937adamleithp wants to merge 2 commits into
adamleithp wants to merge 2 commits into
Conversation
…easure The experimental ChatX thread lagged on scroll where the legacy ConversationView didn't. Three structural gaps, all app-side: - Grouping rebuilt every tool_group/agent_turn wrapper per streamed chunk, so the row memos missed and the whole transcript reconciled on every token. createStableTurnGrouper now reuses a wrapper whenever its member items are reference-equal (the conversation builder freezes completed turns and clones active-turn rows), confining identity churn to the live turn — the same bound the legacy thread gets from createIncrementalThreadGrouper. ThreadItemBody is memoized on item identity for the same reason. - ToolGroup ignored the conversationCollapseMode setting and used uncontrolled defaultOpen, so every group that streamed open stayed expanded (and mounted) for the life of the session. Open state is now controlled with legacy buildThreadGroups semantics — "all" collapses everything, "partial" collapses on turn completion, "none" never — with per-group manual overrides in sessionViewStore, wiped when the mode changes. A closed marker unmounts its body, keeping long transcripts' DOM (and the scroller engine's per-scroll child scans over it) bounded. - The windowed body measured rows via the virtualizer's async ResizeObserver path, painting one frame at the 80px estimate when scrolling through history; it now resizes synchronously on mount like the legacy VirtualizedList, and the diff worker pool is capped at 2 workers to match (the library default of 8 shiki isolates costs hundreds of MB). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EAy2CqYiHQeDTgCEAvAZtG
|
Merging to
After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here |
Both sides added an import at the same spot in ChatThread.tsx: keep the branch's useSessionViewActions (collapse-mode overrides) alongside main's useThreadScrollRequest (activity-pane scroll bridge, #3909).
|
React Doctor found 1 issue in 1 file · 1 warning. 1 warning
Reviewed by React Doctor for commit |
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
The chat thread's tool-run and agent-turn grouping logic was embedded in
ChatThread.tsx, making it hard to test and reuse. Additionally, during streaming, the grouping wrappers (ToolGroupItem,AgentTurn) were recreated on every chunk even when their member items hadn't changed, causing unnecessary re-renders of memoized rows and defeating the performance benefit of memoization.Changes
Extract grouping logic to new module:
threadGrouping.tswithgroupToolRuns(),groupIntoTurns(), and the newcreateStableTurnGrouper()functionisToolCallItem,isInvisibleItem,INVISIBLE_UPDATES) to the new modulethreadGrouping.test.tscovering all grouping scenariosImplement stable wrapper identity:
createStableTurnGrouper()preserves wrapper object identity across calls when member items are reference-equalToolGroupItemandAgentTurnwrappers if their member arrays haven't changedUpdate ChatThread to use stable grouper:
createStableTurnGrouper()once per mounted thread viauseRefturnGrouper.update(items)in the rows memo instead ofgroupIntoTurns(groupToolRuns(items))Update ToolGroup component:
groupIdprop (the run's first tool id) to key manual expand/collapse overridesopenstate instead ofdefaultOpenso groups actually collapse on turn completionUpdate VirtualThreadScrollBody:
measureElementImmediatelycallback to resize rows synchronously on mountUpdate sessionViewStore:
useGroupOverride(id)hook for fine-grained subscription to a single group's overrideHow did you test this?
threadGrouping.test.tscovering:ToolGroup.test.tsxto pass newgroupIdpropAutomatic notifications
https://claude.ai/code/session_01EAy2CqYiHQeDTgCEAvAZtG