perf(web): avoid sidebar visit churn during streaming#4093
Draft
cursor[bot] wants to merge 1 commit into
Draft
Conversation
Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>
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
updatedAtstream chunk.useMarkActiveThreadVisitedhook.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, invalidatingSidebarProjectGroup's visit selector. The unread indicator compares againstlatestTurn.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:
SidebarProjectGrouprendered 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 checkvp run typecheckuiStateStoreandSidebar.logictestsChecklist
To show artifacts inline, enable in settings.
Note
Avoid sidebar visit churn during streaming by extracting
useMarkActiveThreadVisitedhookChatViewContentinto a newuseMarkActiveThreadVisitedhook.latestTurnCompletedAtchanges and is non-null, replacing the previous logic that comparedserverThread.updatedAtagainst a stored last-visited timestamp.completedAtis null), reducing spurious store updates mid-stream.Macroscope summarized 0381ec7.