Repository navigation
fix(minesweeper): practice Play Again now starts a fresh board, not the frozen loss - #917
Merged
Merged
Conversation
…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]>
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.
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
MinesweeperBoardViewbuilds itsMinesweeperGameViewModelin@State'sinitialValue, 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 (itsBoardLoaderViewre-keys via.task(id:)across an async fetch gap); MS Practice had no equivalent loader.Fix
New
MinesweeperFreshBoardLoaderViewwraps the Practice board and attaches.id(BoardKey(difficulty:seed:))to the renderedMinesweeperBoardView, 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 —makeViewModelis synchronous, so there's no async gap to let a.loadingframe render; documented in the file header. Practice/direct-board route only; resume + Daily untouched.Verification
swiftlint --strictclean. New tests assert both the construction seam (fresh independent.idleVM after a real mine-hit loss) AND the.id()wiring (Mirror-reflectedIDViewkeyed on difficulty+seed) — round 1 shipped broken because the old test only checkedmakeViewModelidentity, never the.id().@State); this round applies their prescribed.id()fix.Ready/0:00with all 81 cells hidden (wasBoom/revealed-mines pre-fix).Closes #910
🤖 Generated with Claude Code