fix(ui): reset slug-connect latches on Leave so next game opens WS#159
Merged
fix(ui): reset slug-connect latches on Leave so next game opens WS#159
Conversation
…e roll After a combat roll resolved, the InlineDiceTray's TARGET banner and "Rolled N vs M — Fail" badge stayed pinned through the next narration cycle. When the next action buttons became clickable, the previous roll's numbers were still on screen — players read the stale DC as the target for their next click. App.tsx now clears diceRequest and diceResult inside the NARRATION_END branch (the same turn-boundary signal that re-enables input and clears a resolved confrontation). The InlineDiceTray and DiceOverlay are prop-driven, so both widgets return to a neutral resting state without further changes — the 3D die stays idle until a new DICE_REQUEST triggers the next throw. Added a wiring test in dice-overlay-wiring-34-5.test.ts that asserts both setters are invoked inside the NARRATION_END branch, plus a regression guard that the overlay props still read from the cleared state. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Playtest 2026-04-24 BLOCKING bug: leaving a game and starting a fresh one
(any genre) hung on the post-POST navigate. POST /api/games returned 201
with the new slug, URL flipped to /solo/<new-slug>, but the UI stuck on
"The pages are turning..." indefinitely. Server logs showed NO
ws.connection_accepted, NO mp.slug_connect, NO chargen.phase — the
client never even opened the WebSocket for the new session.
Root cause: react-router-dom v6 reconciles <Routes> children by element
type + position. Our routes "/", "/solo/:slug", and "/play/:slug" all
render <LobbyRoot /> at the same reconciler slot, so React reuses the
AppInner instance across navigate(). All refs survive route changes,
including slugConnectFired.current which latches to true after the first
session's successful fetch + connect. handleLeave reset several refs
(autoReconnectAttempted, seenEventKeys, sessionPhaseRef) but missed this
one and justConnectedRef. On the second game's slug-connect effect run,
the if (slugConnectFired.current) return; gate short-circuited — no
fetch, no WebSocket, no recovery. Typing the URL manually "worked" only
because it triggers a full page reload, which remounts AppInner with
ref defaults.
Not a race — a stale-ref session-lifecycle bug.
Fix:
- Move slugConnectFired ref declaration up to the other session-lifecycle
refs so handleLeave can reset it alongside autoReconnectAttempted.
- handleLeave now clears slugConnectFired.current, justConnectedRef.current,
gameMetaError, and currentGenre so the next game's slug-connect effect
starts from a clean slate.
Wiring test: src/__tests__/lobby-start-ws-open.test.tsx drives the exact
playtest sequence — mount at /solo/first-slug, drive through connect →
ready, click Leave, click Start again. Asserts a fresh WebSocket connects
and SESSION_EVENT{connect, game_slug: second-slug} arrives without any
manual re-navigation. Verified this test FAILS (5s timeout waiting for
secondServer.connected) when the fix is reverted.
Co-Authored-By: Claude Opus 4.7 (1M context) <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.
Summary
Playtest 2026-04-24 BLOCKING bug: leaving a game and starting a fresh one (any genre) hung on the post-POST navigate. POST /api/games returned 201, URL flipped to /solo/, but the UI stuck on "The pages are turning..." indefinitely. Server logs showed no ws.connection_accepted, no mp.slug_connect — the client never opened the WebSocket for the new session.
Root cause
react-router-domv6 reconciles<Routes>children by element type + position. Our routes/,/solo/:slug, and/play/:slugall render<LobbyRoot />at the same reconciler slot, so React reuses the AppInner instance across navigate(). All refs survive route changes, includingslugConnectFired.currentwhich latches totrueafter the first session's successful fetch + connect.handleLeaveresetautoReconnectAttempted,seenEventKeys, andsessionPhaseRefbut missedslugConnectFiredandjustConnectedRef. On the second game's slug-connect effect run, theif (slugConnectFired.current) return;gate short-circuited — no fetch, no WebSocket, no recovery. Typing the URL manually "worked" only because it triggers a full page reload (remounts AppInner with ref defaults).Not a race — a stale-ref session-lifecycle bug.
Fix
slugConnectFiredref declaration up to the other session-lifecycle refs sohandleLeavecan reset it alongsideautoReconnectAttempted.handleLeavenow clearsslugConnectFired.current,justConnectedRef.current,gameMetaError, andcurrentGenreso the next game's slug-connect effect starts from a clean slate.Test plan
src/__tests__/lobby-start-ws-open.test.tsxdrives the exact playtest sequence (mount at/solo/first-slug, drive through connect → ready, click Leave, click Start again) and asserts a fresh WebSocket +SESSION_EVENT{connect, game_slug: second-slug}without any manual re-navigation.slug-routing.test.tsxandConnectScreen.test.tsxstill pass (38/38 in the three touched suites).npx vitest runshows 45 pre-existing failures (unchanged) and 1116 passing — no new regressions.🤖 Generated with Claude Code