Optimize chat composer context updates#3128
Closed
cursor[bot] wants to merge 1 commit into
Closed
Conversation
Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>
Contributor
|
🚀 Expo continuous deployment is ready!
|
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.
What Changed
ChatComposerto subscribe to that selector directly and stopped passing the mutable full thread object / activities array through the memoized composer prop boundary.Why
react-doctorflaggedChatView.tsx/ChatComposer.tsxas React hot spots with state/effect and rerender risks. A manual pass found that streaming/thread activity updates changedactiveThread.activitiesand the fullactiveThreadobject, causing the composer subtree to rerender even when the context-window meter did not change. This keeps the high-frequency timeline updates from invalidating the composer unless composer-relevant data changes.UI Changes
React Scan recordings captured against the same seeded chat route and activity-update scenario:
react_scan_before_context_activity.webm— composer flashes during repeated activity-only updates.react_scan_after_context_activity_v2.webm— thread area still updates, but the composer no longer flashes during the activity-only update phase.Checklist
Validation:
corepack pnpm --filter @t3tools/web test -- src/storeSelectors.test.ts(web unit project: 1198 passed)corepack pnpm exec vp check(run with pre-existing uncommittedpackage.jsonedit temporarily stashed)corepack pnpm exec vp run typecheckNote
Optimize
ChatComposercontext updates by deriving context window snapshot from the storeChatComposernow receives onlyactiveThreadSessionProviderInstanceIdinstead of the fullThreadobject and its activities, reducing unnecessary re-renders when unrelated thread data changes.createContextWindowSnapshotSelectorByRefin storeSelectors.ts, a memoized selector that computes the context window snapshot from the global store and returns a stable reference when unrelated activities are appended or derived values are unchanged.contextWindowSnapshotsEqualin contextWindow.ts to perform field-level equality checks on snapshots, preventing reference churn when values are identical.activeThreadIdrather than the fullactiveThreadobject.Macroscope summarized 487295d.