From 73b40f82565e86240b0b0db9ba3035d7bd491520 Mon Sep 17 00:00:00 2001 From: David Montero Date: Fri, 28 Aug 2026 05:05:11 +0200 Subject: [PATCH] fix(canvas): WiFi badge follows the run, Wokwi-style The badge used to render from the moment a radio-capable board was on the canvas, so a fresh XIAO ESP32-S3 project showed a WiFi icon before Run was ever pressed. Now it appears when the simulation starts (gray while the stack boots, green on got_ip) and leaves on Stop. startBoard also clears the board's stale wifiStatus/bleStatus: they were never reset, so a re-run would have opened the badge showing the previous run's association. --- .../src/components/simulator/SimulatorCanvas.tsx | 8 +++++--- frontend/src/store/useSimulatorStore.ts | 12 ++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/frontend/src/components/simulator/SimulatorCanvas.tsx b/frontend/src/components/simulator/SimulatorCanvas.tsx index b470a94e..c952d129 100644 --- a/frontend/src/components/simulator/SimulatorCanvas.tsx +++ b/frontend/src/components/simulator/SimulatorCanvas.tsx @@ -2854,10 +2854,12 @@ export const SimulatorCanvas = ({ headerSlot }: SimulatorCanvasProps = {}) => { {/* WiFi status indicator + IoT-gateway launcher (ESP32 + Pico W). - Renders from the moment a radio-capable board is active — - before a Run it shows as disconnected, so the icon is a - stable place to click (the overlay hangs its panel off it). */} + Wokwi-style lifecycle: nothing until Run. The badge appears + with the simulation (gray while the stack boots, green on + got_ip) and leaves on Stop. The overlay hangs its WiFi + panel off it while it is up. */} {activeBoard && + activeBoard.running && (isEsp32Kind(activeBoard.boardKind) || activeBoard.boardKind === 'pi-pico-w') && (() => { // The Pico W virtual net assigns its IP deterministically when diff --git a/frontend/src/store/useSimulatorStore.ts b/frontend/src/store/useSimulatorStore.ts index 2325f952..9902090b 100644 --- a/frontend/src/store/useSimulatorStore.ts +++ b/frontend/src/store/useSimulatorStore.ts @@ -2340,6 +2340,18 @@ export const useSimulatorStore = create((set, get) => { const board = get().boards.find((b) => b.id === boardId); if (!board) return; + // A fresh run starts with a clean radio state. The WiFi/BLE badges are + // only visible while the board runs, and nothing else clears them, so + // without this a re-run opens showing the PREVIOUS run's association + // (a green got_ip badge for a connection nothing has made yet). + if (board.wifiStatus || board.bleStatus) { + set((s) => ({ + boards: s.boards.map((b) => + b.id === boardId ? { ...b, wifiStatus: undefined, bleStatus: undefined } : b, + ), + })); + } + // Pro gate (run backstop): catches STM32/Pi boards that entered the // canvas via an example or a loaded project (which bypass the picker's // add gate). Non-paid web users get the upgrade prompt instead of a run.