Skip to content

feat: Add React Scan WebSocket harness with environment initialization fix#2931

Draft
cursor[bot] wants to merge 4 commits into
mainfrom
cursor/component-performance-optimization-f654
Draft

feat: Add React Scan WebSocket harness with environment initialization fix#2931
cursor[bot] wants to merge 4 commits into
mainfrom
cursor/component-performance-optimization-f654

Conversation

@cursor
Copy link
Copy Markdown
Contributor

@cursor cursor Bot commented Jun 3, 2026

Summary

Created a React Scan test harness to observe rerender behavior in the WebSocket reconnect toast, and fixed a critical bug preventing the harness from functioning.

Changes

  • Added react-scan-ws-harness.html and reactScanWsHarness.tsx files
  • Implemented initializeMockEnvironment() to fix "Unable to resolve the primary environment" error
  • Added WebSocket state seeding to create reconnect-waiting conditions
  • Added console logging for debugging connection state

Testing & Observations

Test Goal: Observe whether React Scan detects and highlights rerenders in the WebSocket reconnect toast countdown.

Current Status: The toast does not visibly appear or update.

Findings:

  1. ✅ React Scan toolbar is visible (bottom-right corner)
  2. ✅ Fixed critical environment initialization bug
  3. ✅ WebSocket state correctly shows uiState: "reconnecting" with hasConnected: true
  4. ❌ Toast does not render despite correct state

Root Cause: The harness seeds WebSocket reconnect state but lacks full environment connection infrastructure. Specifically:

  • WebSocketConnectionCoordinator requires getPrimaryEnvironmentConnection().reconnect() to be callable
  • Only the environment descriptor was mocked, not the full connection object with WebSocket client and reconnect method
  • Toast infrastructure depends on complete environment connection setup

Recommendations

To complete this harness:

  1. Mock createEnvironmentConnection() with a stub WebSocket client
  2. Provide a noop reconnect() method that prevents errors when "Retry now" is clicked
  3. OR: Create a simpler test component that directly uses toastManager.add() to demonstrate React Scan rerender detection without relying on WebSocketConnectionCoordinator

Answer to Test Question

Does the WebSocket reconnect toast visibly update/rerender?

No. The toast does not appear at all, so React Scan cannot demonstrate rerender detection on it. The WebSocket coordinator state is correctly set to "reconnecting", but the toast rendering pipeline fails because the harness lacks full environment connection mocking.

Open in Web View Automation 

Note

Add React Scan WebSocket harness for testing reconnect-waiting UI state

  • Adds react-scan-ws-harness.html as a standalone entry point that loads the react-scan instrumentation script and mounts reactScanWsHarness.tsx.
  • initializeMockEnvironment writes a deterministic mock ExecutionEnvironmentDescriptor (id: harness-mock-env) so the app has a valid environment on load.
  • seedReconnectWaitingState drives the in-memory WS connection state through multiple failed attempts (close code 1006) to produce a reconnect-waiting scenario, logging the derived status and UI state.
  • HarnessView renders ToastProvider wrapping WebSocketConnectionCoordinator and exposes a button to re-trigger the reconnect seed without a full page reload.

Macroscope summarized 85d1517. (Automatic summaries will resume when PR exits draft mode or review begins).

…nt initialization

- Create react-scan-ws-harness.html and reactScanWsHarness.tsx for testing React Scan performance monitoring
- Initialize mock primary environment to prevent 'Unable to resolve primary environment' error
- Seed WebSocket reconnect-waiting state for toast testing
- Add console logging to debug connection state

The harness sets up a test environment to observe whether React Scan can detect rerenders
in the WebSocket reconnect toast countdown. The toast infrastructure requires additional
WebSocket connection mocking to fully function.

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 Jun 3, 2026
cursoragent and others added 3 commits June 3, 2026 16:29
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>
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