Fix launch crash, infinite spinner, and HealthKit data loading - #29
Closed
gsbernstein wants to merge 2 commits into
Closed
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 at launch (
BedtimeApp.swift:23), plus an infinite loading spinner after reinstall, plus sleep data not appearing.Root causes
ModelContainercreation failed and hitfatalErrorbefore any UI loaded..taskleft HealthKit in.loading— seeding preferences and fetching HealthKit data shared one.taskon a view whose identity changed when@Querypopulated, so SwiftUI cancelled it mid-flight and the permission state never advanced.loadSleepData()returned beforeHKSampleQuerycallbacks ran, so the UI could leave the loading state before data arrived.