fix(web): stabilize useListen so transient board-state events aren't dropped#80
Merged
Conversation
…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>
8a2320b to
bda6457
Compare
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 fastconnecting→connectedburst from firmata detection. The steady terminalconnectedstate survived; the transientconnectingframe was lost, so the spinner never rendered.The
connectingstate 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-typesclean. Manual: connect a board, the "Connecting" pill + spinningLoaderPinwheelIconshow during the ~1-3s detection window.🤖 Generated with Claude Code