Skip to content

Optimize chat composer context updates#3128

Closed
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/component-performance-optimization-8995
Closed

Optimize chat composer context updates#3128
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/component-performance-optimization-8995

Conversation

@cursor

@cursor cursor Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

What Changed

  • Added a stable context-window selector for chat threads so activity-only updates reuse the previous context-window snapshot.
  • Updated ChatComposer to subscribe to that selector directly and stopped passing the mutable full thread object / activities array through the memoized composer prop boundary.
  • Added selector tests covering reuse on unrelated activity appends and refresh on real context-window updates.

Why

react-doctor flagged ChatView.tsx / ChatComposer.tsx as React hot spots with state/effect and rerender risks. A manual pass found that streaming/thread activity updates changed activeThread.activities and the full activeThread object, 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:

  • Before: react_scan_before_context_activity.webm — composer flashes during repeated activity-only updates.
  • After: react_scan_after_context_activity_v2.webm — thread area still updates, but the composer no longer flashes during the activity-only update phase.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes
  • I included a video for animation/interaction changes

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 uncommitted package.json edit temporarily stashed)
  • corepack pnpm exec vp run typecheck
Open in Web View Automation 

Note

Optimize ChatComposer context updates by deriving context window snapshot from the store

  • ChatComposer now receives only activeThreadSessionProviderInstanceId instead of the full Thread object and its activities, reducing unnecessary re-renders when unrelated thread data changes.
  • Adds createContextWindowSnapshotSelectorByRef in 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.
  • Adds contextWindowSnapshotsEqual in contextWindow.ts to perform field-level equality checks on snapshots, preventing reference churn when values are identical.
  • Behavioral Change: terminal context insertion now requires activeThreadId rather than the full activeThread object.

Macroscope summarized 487295d.

Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>
@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels Jun 17, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Expo continuous deployment is ready!

  • Project → t3-code
  • Platforms → android, ios
  • Scheme → t3code-preview
  🤖 Android 🍎 iOS
Fingerprint 052dc86843f08d733f88b4c444db61397f6e5117 56f0ff9f61b9906d203c2fea265e3f9507332117
Build Details Build Permalink
DetailsDistribution: INTERNAL
Build profile: preview:dev
Runtime version: 052dc86843f08d733f88b4c444db61397f6e5117
App version: 0.1.0
Git commit: d3ad7eeecc40682bc33c73faa1819d353d3698e1
Build Permalink
DetailsDistribution: INTERNAL
Build profile: preview:dev
Runtime version: 56f0ff9f61b9906d203c2fea265e3f9507332117
App version: 0.1.0
Git commit: d3ad7eeecc40682bc33c73faa1819d353d3698e1
Update Details Update Permalink
DetailsBranch: pr-3128
Runtime version: 052dc86843f08d733f88b4c444db61397f6e5117
Git commit: d3ad7eeecc40682bc33c73faa1819d353d3698e1
Update Permalink
DetailsBranch: pr-3128
Runtime version: 56f0ff9f61b9906d203c2fea265e3f9507332117
Git commit: d3ad7eeecc40682bc33c73faa1819d353d3698e1
Update QR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants