Skip to content

fix(minesweeper): practice Play Again now starts a fresh board, not the frozen loss - #917

Merged
wei18 merged 1 commit into
mainfrom
fix/910-ms-practice-play-again
Jul 20, 2026
Merged

wei18 merged 1 commit into
mainfrom
fix/910-ms-practice-play-again

Conversation

@wei18

@wei18 wei18 commented Jul 20, 2026

Copy link
Copy Markdown
Owner

What

MS Practice → hit a mine → Play Again now starts a genuinely fresh board instead of leaving the frozen exploded loss (all mines revealed) on screen.

Root cause

MinesweeperBoardView builds its MinesweeperGameViewModel in @State's initialValue, which SwiftUI only honors on first structural-identity creation. Play Again's same-tick dismiss+represent reused that identity, so the fresh seed's VM was discarded and the old lost VM kept driving the board. Sudoku was unaffected (its BoardLoaderView re-keys via .task(id:) across an async fetch gap); MS Practice had no equivalent loader.

Fix

New MinesweeperFreshBoardLoaderView wraps the Practice board and attaches .id(BoardKey(difficulty:seed:)) to the rendered MinesweeperBoardView, so a seed change forces SwiftUI to tear down the stale board and mount a fresh one. .id() (not the sibling loaders' state = .loading) is used deliberately — makeViewModel is synchronous, so there's no async gap to let a .loading frame render; documented in the file header. Practice/direct-board route only; resume + Daily untouched.

Verification

  • MinesweeperKit 365 tests + swiftlint --strict clean. New tests assert both the construction seam (fresh independent .idle VM after a real mine-hit loss) AND the .id() wiring (Mirror-reflected IDView keyed on difficulty+seed) — round 1 shipped broken because the old test only checked makeViewModel identity, never the .id().
  • Dual CR: round 1 REJECTED (both reviewers caught the fix reproducing the bug one level down in the nested @State); this round applies their prescribed .id() fix.
  • Leader sim-verified on a clean-DerivedData build: Play Again after a real loss now yields Ready/0:00 with all 81 cells hidden (was Boom/revealed-mines pre-fix).

Closes #910

🤖 Generated with Claude Code

…he frozen loss

MS Practice → hit a mine → Play Again left the board frozen on the exploded
state with all mines revealed. MinesweeperBoardView builds its game VM in
@State's initialValue, which SwiftUI only honors on first structural-identity
creation; Play Again's same-tick dismiss+represent reused that identity, so
the new seed's VM was discarded and the old lost VM kept driving the board.
(Sudoku was unaffected — its BoardLoaderView already re-keys via .task(id:)
over an async fetch gap; MS Practice had no such loader.)

Fix: new MinesweeperFreshBoardLoaderView wraps the Practice board and attaches
.id(BoardKey(difficulty:seed:)) to the rendered MinesweeperBoardView. On a
seed change SwiftUI assigns a new identity → the old board (with its stale
@State) is torn down and a fresh one mounts. Note the deliberate deviation
from the sibling loaders' state=.loading mechanism: their load() has a real
async fetch that lets .loading render; this loader's makeViewModel is
synchronous, so .id() (not a rendered .loading frame) is the reliable trigger
— documented in the file header.

Wired only into the Practice/direct-board route (LiveRouteFactory+DailyBoardOpen);
resume + Daily paths untouched. Tests: a construction-seam test (fresh
independent .idle VM after a real mine-hit loss) PLUS two Mirror-based tests
asserting the .id() IDView wrapper is present and keyed on (difficulty,seed) —
the round-1 fix shipped broken precisely because the old test only checked
makeViewModel identity, never the .id() wiring.

Verified: MinesweeperKit 365 tests + swiftlint --strict clean; dual CR
identified the exact .id() fix (round 1 REJECTED for reproducing the bug one
level down in the nested @State); Leader sim-verified on a clean-DerivedData
build — Play Again after a real loss now yields Ready/0:00 with all 81 cells
hidden (was Boom/revealed-mines pre-fix).

Closes #910

Co-Authored-By: Claude Fable 5 <[email protected]>
@wei18
wei18 enabled auto-merge (squash) July 20, 2026 15:40
@wei18
wei18 merged commit 2929059 into main Jul 20, 2026
5 checks passed
@wei18
wei18 deleted the fix/910-ms-practice-play-again branch July 20, 2026 15:41
@wei18 wei18 mentioned this pull request Jul 21, 2026
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.

fix(minesweeper): practice "Play Again" leaves the exploded board frozen, no new game

1 participant