From 85d15178b54e1daceb182c9c8336aabe71f92f03 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Wed, 3 Jun 2026 16:17:28 +0000 Subject: [PATCH] feat: Add React Scan WebSocket reconnect toast harness with environment 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 --- apps/web/react-scan-ws-harness.html | 13 ++++ apps/web/src/reactScanWsHarness.tsx | 100 ++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 apps/web/react-scan-ws-harness.html create mode 100644 apps/web/src/reactScanWsHarness.tsx diff --git a/apps/web/react-scan-ws-harness.html b/apps/web/react-scan-ws-harness.html new file mode 100644 index 0000000000..d317ac8957 --- /dev/null +++ b/apps/web/react-scan-ws-harness.html @@ -0,0 +1,13 @@ + + + + + + + React Scan WebSocket Toast Harness + + +
+ + + diff --git a/apps/web/src/reactScanWsHarness.tsx b/apps/web/src/reactScanWsHarness.tsx new file mode 100644 index 0000000000..7288b2e4b6 --- /dev/null +++ b/apps/web/src/reactScanWsHarness.tsx @@ -0,0 +1,100 @@ +import React, { useEffect } from "react"; +import ReactDOM from "react-dom/client"; +import { createRootRoute, createRouter, RouterProvider } from "@tanstack/react-router"; +import { EnvironmentId, type ExecutionEnvironmentDescriptor } from "@t3tools/contracts"; + +import "./index.css"; + +import { WebSocketConnectionCoordinator } from "./components/WebSocketConnectionSurface"; +import { ToastProvider } from "./components/ui/toast"; +import { + getWsConnectionStatus, + getWsConnectionUiState, + recordWsConnectionAttempt, + recordWsConnectionClosed, + recordWsConnectionOpened, + resetWsConnectionStateForTests, +} from "./rpc/wsConnectionState"; +import { writePrimaryEnvironmentDescriptor } from "./environments/primary/context"; + +function initializeMockEnvironment() { + const mockDescriptor: ExecutionEnvironmentDescriptor = { + environmentId: EnvironmentId.make("harness-mock-env"), + label: "React Scan Harness Mock", + platform: { + os: "darwin", + arch: "arm64", + }, + serverVersion: "0.0.0-test", + capabilities: { + repositoryIdentity: false, + }, + }; + + writePrimaryEnvironmentDescriptor(mockDescriptor); +} + +function seedReconnectWaitingState() { + resetWsConnectionStateForTests(); + recordWsConnectionAttempt("ws://localhost:9999", { connectionLabel: "React Scan Harness" }); + recordWsConnectionOpened({ connectionLabel: "React Scan Harness" }); + for (let index = 0; index < 5; index += 1) { + recordWsConnectionAttempt("ws://localhost:9999", { connectionLabel: "React Scan Harness" }); + recordWsConnectionClosed( + { code: 1006, reason: "Harness disconnect" }, + { + connectionLabel: "React Scan Harness", + }, + ); + } + + const status = getWsConnectionStatus(); + const uiState = getWsConnectionUiState(status); + console.log("[Harness] WS status after seed:", { status, uiState }); +} + +function HarnessView() { + useEffect(() => { + initializeMockEnvironment(); + seedReconnectWaitingState(); + }, []); + + return ( + + +
+
+

+ React Scan harness +

+

WebSocket reconnect toast

+

+ The WebSocket coordinator is in a reconnect-waiting state. React Scan is enabled to show + whether the toast stack keeps rerendering while the countdown is visible. +

+ +
+
+
+ ); +} + +const rootRoute = createRootRoute({ + component: HarnessView, +}); + +const router = createRouter({ + routeTree: rootRoute, +}); + +ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render( + + + , +);