Skip to content

fix(ui): refresh stale screens after data changes (coach edit, goals, metric detail)#88

Merged
saksham2001 merged 3 commits into
saksham2001:mainfrom
rgvxsthi:fix/data-reactivity
Jul 15, 2026
Merged

fix(ui): refresh stale screens after data changes (coach edit, goals, metric detail)#88
saksham2001 merged 3 commits into
saksham2001:mainfrom
rgvxsthi:fix/data-reactivity

Conversation

@rgvxsthi

Copy link
Copy Markdown
Contributor

Three independent reactivity gaps where a write didn't reach the UI until an unrelated sync or an app relaunch. Found via a code audit; all hit connected-ring users.

1. Coach editing today's workout left Today/Activity stale + corrupted aggregates

ActionTools.applyUpdatesNow (the immediate path for a today-dated session) set session.type/startedAt/endedAt/distance directly and called save() — but never bumped the change token and never routed through ActivityService.applyEdit. So after "make today's run 45 min" the workout card updated while Today/Activity kept the old duration/distance/calories, and the daily rollup was computed off stale fields. Now mirrors the confirmed-edit path in PendingActionExecutor (route type/time through applyEdit, apply a user-stated distance after, then notify()).

2. Goal edits didn't re-fill Today's rings until a sync/relaunch

GoalsSettingsView.save() persisted the UserGoal but never bumped the token, and goal targets aren't part of TodayStore's signature — so the rings kept filling against the old goal. Added PulseDataChange.shared.notify() after save.

3. MetricDetailView went stale on a sync while open

Its only data trigger was .task(id: period) into @State. A background sync completing while the detail was open left its chart + Latest/Avg/Min/Max tiles showing pre-sync numbers (disagreeing with the dashboard behind it). Now observes PulseDataChange.token and reloads, matching Today/Vitals.

Builds green.

… metric detail)

Three reactivity gaps where a write didn't reach the UI until an unrelated
sync or relaunch:

- Coach editing a *today* workout used `applyUpdatesNow`, which set the
  session fields directly and never bumped the change token or routed
  through `ActivityService.applyEdit` — so Today/Activity showed the old
  duration/distance/calories and the daily rollup was computed off stale
  fields. Route type/time through the edit service and notify(), matching
  the confirmed-edit path in `PendingActionExecutor`.
- Editing a daily Goal persisted the `UserGoal` but never bumped the token,
  and goal targets aren't in Today's data signature, so the rings kept
  filling against the old goal. notify() after save.
- MetricDetailView only reloaded on the period segment; a sync completing
  while it was open left its chart + Latest/Avg/Min/Max tiles stale.
  Observe `PulseDataChange.token` and reload.
@saksham2001
saksham2001 merged commit e937a39 into saksham2001:main Jul 15, 2026
2 checks passed
@rgvxsthi
rgvxsthi deleted the fix/data-reactivity branch July 16, 2026 04:20
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.

2 participants