Skip to content

fix(web): stabilize useListen so transient board-state events aren't dropped#80

Merged
xiduzo merged 2 commits into
mainfrom
fix/board-connecting-spinner
Jun 20, 2026
Merged

fix(web): stabilize useListen so transient board-state events aren't dropped#80
xiduzo merged 2 commits into
mainfrom
fix/board-connecting-spinner

Conversation

@xiduzo

@xiduzo xiduzo commented Jun 20, 2026

Copy link
Copy Markdown
Owner

Problem

Backend logs showed the microcontroller being detected/connected, but the UI never showed the Connecting spinner — it jumped straight from "No microcontroller connected" to connected.

Root cause

useListen (src/lib/ipc.ts) re-created the Tauri event listener on every render: callers pass a fresh inline { type, handler } object and the effect depended on [event]. The unlisten/relisten gap dropped events arriving mid-render — notably the fast connectingconnected burst from firmata detection. The steady terminal connected state survived; the transient connecting frame was lost, so the spinner never rendered.

The connecting state and spinner styling already existed (nav-microcontroller.tsx, BoardState.ts) — they just never received the event.

Fix

Route the handler through a ref and subscribe once per event type. The listener is now stable across renders, so transient events are no longer dropped. This is a shared hook, so every consumer (board state, mqtt, broker, component events) benefits.

Verification

bun run check-types clean. Manual: connect a board, the "Connecting" pill + spinning LoaderPinwheelIcon show during the ~1-3s detection window.

🤖 Generated with Claude Code

…dropped

useListen re-created the Tauri listener on every render because callers
pass a fresh inline { type, handler } object and the effect depended on
[event]. The unlisten/relisten gap dropped events arriving mid-render —
notably the fast connecting->connected burst, so the "Connecting" spinner
never showed. Route the handler through a ref and subscribe once per type.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@xiduzo xiduzo closed this Jun 20, 2026
@xiduzo xiduzo reopened this Jun 20, 2026
@xiduzo xiduzo force-pushed the fix/board-connecting-spinner branch from 8a2320b to bda6457 Compare June 20, 2026 10:00
Clippy's match_wildcard_for_single_variants flagged the `_` arm in the
CompareValidator match, which now covers only the Boolean variant. Name it
explicitly so a future added variant is a compile error instead of silently
falling through to boolean truthiness.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@xiduzo xiduzo merged commit f983783 into main Jun 20, 2026
7 checks passed
@xiduzo xiduzo deleted the fix/board-connecting-spinner branch June 20, 2026 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant