Skip to content

Avoid WebSocket coordinator countdown rerenders#2647

Draft
cursor[bot] wants to merge 3 commits into
mainfrom
cursor/react-performance-optimization-3ecc
Draft

Avoid WebSocket coordinator countdown rerenders#2647
cursor[bot] wants to merge 3 commits into
mainfrom
cursor/react-performance-optimization-3ecc

Conversation

@cursor
Copy link
Copy Markdown
Contributor

@cursor cursor Bot commented May 11, 2026

What Changed

  • Removed countdown nowMs React state from WebSocketConnectionCoordinator so the reconnect toast countdown no longer re-renders the coordinator every second.
  • Moved the coordinator side effects into a named hook, useWebSocketConnectionCoordinatorEffects, and refreshed the reconnect toast via an effect event instead of render-driving state.
  • Added react-scan before/after evidence artifacts:
    • docs/performance/react-scan-websocket-coordinator-before.webm
    • docs/performance/react-scan-websocket-coordinator-after.webm
    • docs/performance/react-scan-websocket-coordinator-before.json
    • docs/performance/react-scan-websocket-coordinator-after.json

Why

React Doctor flagged WebSocketConnectionSurface.tsx with rerender-state-only-in-handlers: nowMs was updated for countdown bookkeeping but never rendered by the component. In the reconnect waiting state this caused avoidable coordinator update renders once per second. The toast still updates on the same cadence, but the coordinator no longer needs to re-render for those ticks.

React-scan/Profiler capture summary over the same ~5.5s reconnect countdown harness:

  • Before: 9 coordinator renders, 8 update renders.
  • After: 2 coordinator renders, 1 update render.

UI Changes

No product UI behavior change intended. The committed .webm files are before/after screen recordings with react-scan enabled for the reconnect countdown harness.

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:

  • bun fmt
  • bun lint
  • bun typecheck
  • bunx --bun react-doctor@latest . --diff main --verbose --json --offline --fail-on none
Open in Web View Automation 

Note

Avoid 1s interval re-renders in WebSocketConnectionCoordinator

  • Extracts coordinator side-effect logic into a new useWebSocketConnectionCoordinatorEffects hook in WebSocketConnectionSurface.tsx, removing nowMs state and its interval-driven updates.
  • The periodic toast sync for the 'waiting' reconnect phase now calls a syncConnectionToast callback directly on a timer instead of updating React state, eliminating 1s re-renders on the coordinator component.
  • Performance before/after captures are included in docs/performance/ to document the improvement.

Macroscope summarized f9a634d.

cursoragent and others added 3 commits May 11, 2026 16:21
Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>
Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>
Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>
@github-actions github-actions Bot added size:L 100-499 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. labels May 11, 2026
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.

1 participant