Skip to content

perf(web): avoid sidebar visit churn during streaming - #4093

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

perf(web): avoid sidebar visit churn during streaming#4093
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/component-performance-optimization-6106

Conversation

@cursor

@cursor cursor Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

What Changed

  • Mark the active thread visited when its latest turn completes instead of on every updatedAt stream chunk.
  • Move the necessary external-store synchronization into the named useMarkActiveThreadVisited hook.

Why

React Doctor and a manual hot-spot pass identified ChatViewContent/sidebar state fan-out as a high-frequency path. Each streamed chunk previously wrote a new visit timestamp to Zustand, invalidating SidebarProjectGroup's visit selector. The unread indicator compares against latestTurn.completedAt, so recording that timestamp once preserves read/unread behavior while removing intermediate writes.

UI Changes

React Scan was enabled for the same simulated 20-chunk turn in both recordings.

Before: SidebarProjectGroup rendered 20 extra times (2 → 22), with a React Scan highlight on every chunk.

react_scan_thread_visit_before.mp4

After: it stayed stable through streaming and rendered once at completion (1 → 2).

react_scan_thread_visit_after.mp4

Validation

  • vp check
  • vp run typecheck
  • 71 focused uiStateStore and Sidebar.logic tests
  • React Doctor performance scan (remaining findings are pre-existing and outside this focused fix)

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

To show artifacts inline, enable in settings.

Open in Web View Automation 

Note

Avoid sidebar visit churn during streaming by extracting useMarkActiveThreadVisited hook

  • Extracts visitation-tracking logic from ChatViewContent into a new useMarkActiveThreadVisited hook.
  • The hook marks a thread visited whenever latestTurnCompletedAt changes and is non-null, replacing the previous logic that compared serverThread.updatedAt against a stored last-visited timestamp.
  • Behavioral Change: visited marking no longer fires during streaming (when completedAt is null), reducing spurious store updates mid-stream.

Macroscope summarized 0381ec7.

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

t3-code Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

closing as superseded by #5486. that merged change removes automatic visit-on-view/update behavior, so the streaming-time visit writes this pr optimizes no longer exist. thanks for the work here.

@t3-code t3-code Bot closed this Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 30-99 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.

1 participant