Skip to content

fix(daily-hub): stabilise view-model ownership via @State — fixes infinite spinner online+signed-out (#536) - #537

Merged
wei18 merged 3 commits into
mainfrom
fix/536-dailyhub-vm-ownership
Jun 16, 2026
Merged

wei18 merged 3 commits into
mainfrom
fix/536-dailyhub-vm-ownership

Conversation

@wei18

@wei18 wei18 commented Jun 16, 2026

Copy link
Copy Markdown
Owner

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 the DailyHubViewModel inline inside the .navigationDestination closure. 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 .idle VM, and the view bound to it. Because the view keeps the same SwiftUI identity, .task does not re-fire for the new instance → it stays .idle forever. 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

  • Empirical sim proof (the real regression guard for this class): clean Debug build, iPhone 17 Pro, online + iCloud signed out:
    • Sudoku Daily Hub renders Easy/Medium/Hard; tapping Easy opens the board (99 elements).
    • Minesweeper Daily Hub renders Beginner/Intermediate/Expert.
    • Both previously stuck on an infinite spinner on the same build lineage.
  • swift test: SudokuKit 251/251, MinesweeperKit 179/179 pass.
  • SwiftLint --strict clean on changed files.
  • Code review (Code Reviewer subagent): APPROVE-WITH-NITS, no blockers.

Known limitation (honest)

The added DailyHubViewOwnershipTests document the model-layer invariant the @State fix 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 stores Binding directly vs Sudoku's RoutePath) 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

wei18 and others added 3 commits June 16, 2026 21:44
…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]>
@wei18
wei18 merged commit cbd2d5d into main Jun 16, 2026
4 checks passed
@wei18
wei18 deleted the fix/536-dailyhub-vm-ownership branch June 16, 2026 14:43
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.

Daily Hub infinite spinner when online + iCloud signed out — transient view-model orphaned by destination re-render (both apps)

1 participant