Repository navigation
fix(daily-hub): stabilise view-model ownership via @State — fixes infinite spinner online+signed-out (#536) - #537
Merged
Merged
Conversation
…nner (#536) `DailyHubView` and `MinesweeperDailyHubView` stored the injected VM via `@Bindable` (plain property assignment). When SwiftUI's `.navigationDestination` closure re-invoked `LiveRouteFactory.view(for:)` during an AdMob banner WebView load, the factory minted a fresh `.idle` DailyHubViewModel. The view's `@Bindable` var was reassigned to this new instance; because SwiftUI kept the same view identity, `.task { bootstrap() }` did NOT re-fire — leaving the new VM stuck at `.idle` forever (infinite spinner). The original bootstrapped VM was orphaned. Fix: change `@Bindable` → `@State` with `_viewModel = State(wrappedValue:)` in both views. `@State` first-value-wins semantics mean SwiftUI retains the FIRST bootstrapped instance for the navigation entry's lifetime; subsequent factory invocations that mint fresh idle VMs are ignored by SwiftUI's property-wrapper diffing. No change to VM logic, factory, or navigation wiring. Adds `DailyHubViewOwnershipTests` pinning the model invariants the fix relies on (bootstrapped VM keeps .loaded; factory re-mints start .idle; both are distinct objects). Both packages green: SudokuKit 251/251, MinesweeperKit 179/179. Co-Authored-By: Claude <[email protected]>
SwiftLint --strict: identifier_name requires ≥ 3 chars; `vm` tripped the warning in DailyHubViewOwnershipTests. Rename to `viewModel` to match the convention used throughout the suite. No logic change. Co-Authored-By: Claude <[email protected]>
Daily Hub cases #1/#2 flipped pend→pass after the #536 fix (transient DailyHubViewModel orphaned by destination re-render → infinite spinner when online + iCloud signed out). Also marks this session's independent sim verifications: MS Loss Boom overlay, MS dark-mode cell tri-state, MS per-cell VoiceOver labels. Now 20 pass / 0 fail / 23 pend. Co-Authored-By: Claude Opus 4.8 <[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.
Fixes #536.
Bug
Daily Hub showed an infinite spinner (cards never render) when the device is online but signed out of iCloud, on both apps. This is the normal config for an online user who hasn't signed into iCloud — Daily mode is unusable for them.
Root cause (instrumented, see #536 for the os_log timeline)
LiveRouteFactory.view(for:)builds theDailyHubViewModelinline inside the.navigationDestinationclosure. The destination view stored it as@Bindable, so a destination re-render (in production: the AdMob banner WebView finishing its network load) re-invoked the factory, minted a fresh.idleVM, and the view bound to it. Because the view keeps the same SwiftUI identity,.taskdoes not re-fire for the new instance → it stays.idleforever. The original VM that reached.loaded([3 cards])is orphaned. Offline worked only because the banner never loads, so no re-render occurred.Fix
Make the destination view own its view-model via
@State(first-value-wins) instead of@Bindable, so the first bootstrapped instance is retained for the navigation entry's lifetime. Two-line change per app; the factory and the two-phase render logic are untouched. Mirrored across Sudoku + Minesweeper.Verification
swift test: SudokuKit 251/251, MinesweeperKit 179/179 pass.--strictclean on changed files.Known limitation (honest)
The added
DailyHubViewOwnershipTestsdocument the model-layer invariant the@Statefix relies on but do not fail-first (the regression lives in the SwiftUI property-wrapper layer, not the model). This repo has no ViewInspector and CI cannot run UI tests, so the sim audit is the verification of record for this fix — consistent with the Phase 3 interactive-audit methodology that found the bug. Pre-existing arch debt noted by review (MS VM storesBindingdirectly vs Sudoku'sRoutePath) is out of scope here.Includes a Phase 3 test-plan doc bump (v6): #1/#2 flip to pass, plus three independent MS sim verifications from the same session.
🤖 Generated with Claude Code