Fix launch crash, infinite spinner, and HealthKit data loading - #29
Draft
gsbernstein wants to merge 2 commits into
Draft
Fix launch crash, infinite spinner, and HealthKit data loading#29gsbernstein wants to merge 2 commits into
gsbernstein wants to merge 2 commits into
Conversation
- Stop inserting UserPreferences during view body evaluation; seed defaults in a task and gate the main UI on the persisted @query result instead. - Recover from incompatible SwiftData stores by deleting stale files and retrying container creation (covers upgrades where delete/reinstall may still restore an old store via iCloud backup). - Guard LastNightCard against an empty session array. Co-authored-by: Greg <gsbernstein@users.noreply.github.com>
- Start the initial HealthKit fetch from HealthKitManager.init so it is not cancelled when ContentView switches from the preferences seeding state to the main UI (which left permissionsRequestState stuck at .loading). - Await HKSampleQuery results before returning from fetchSleepData so sleep data is populated before the UI leaves the loading state. - Add resumeLoadingIfNeeded() as a safety net on the main content view. Co-authored-by: Greg <gsbernstein@users.noreply.github.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.
Problem
TestFlight crash log confirms launch failure at
BedtimeApp.swift:23—fatalErrorwhen SwiftData can't open the store after the #20 schema change.A follow-up report after delete/reinstall: app opens but shows an infinite loading spinner (nav bar visible, no cards). That matches
permissionsRequestStatestuck at.loading.Root causes
1. SwiftData store incompatible after #20 (crash)
ModelContainercreation fails →fatalErrorbefore any UI loads.2. Cancelled
.taskleft HealthKit in.loading(spinner)PR #29 initially combined preferences seeding and HealthKit fetch in one
.taskon aGroupwhose child identity changes when@Querypopulates. SwiftUI cancels that task mid-flight, sofetchSleepData's defer never runs andpermissionsRequestStatestays.loadingforever.3. HealthKit queries were fire-and-forget
loadSleepData()returned beforeHKSampleQuerycallbacks, so the UI could leave loading before data arrived (explains "home screen but no sleep data").Fix
ModelContainerfailure (delete store +-shm/-wal, retry).taskon the loading branch only; no insert during view bodyHealthKitManager.init(not tied to view lifecycle)resumeLoadingIfNeeded()safety net on main contentfetchSleepDataVerification