fix(web): keep loading newer timeline days after reload #910

Merged
chris merged 3 commits from fix/newer-days-hydration into main 2026-09-27 12:55:50 +02:00
Owner

Root cause (empirically reproduced on the unpatched build)

After reloading into a restored mid-timeline window, scrolling up fired exactly one revealPreviousDays batch and then stalled with the "Show newer days" button still visible:

  1. One-shot IntersectionObserver: the top sentinel observer (rootMargin: '900px 0px') fires only on intersection transitions. After a restore places the viewport far below the sentinel, the first upward approach consumes the single transition; the sentinel then stays inside the margin, so no further callbacks ever fire. In-session axis jumps mask this because days above are already hydrated.
  2. Dropped calls while loading: revealPreviousDays early-returned when loadingVisibleDays was true — a manual click or observer call landing during an in-flight batch was silently lost.

Reproduced deterministically with a request-gated fixture: window frozen at visibleDayStartIndex = 6, item requests frozen at 18, sentinel still in the margin.

Fix (apps/web/src/routes/+page.svelte, minimal)

  • hydrateDays's finally (winning loadSequence only) now calls schedulePreviousDaysRevealCheck(), which after tick() re-evaluates the margin condition (sentinel.getBoundingClientRect().top < innerHeight + 900) and re-triggers revealPreviousDays() — a condition-driven loop that chains 8-day batches until the sentinel leaves the margin or the window reaches index 0.
  • revealPreviousDays no longer drops calls during in-flight loads: it sets pendingPreviousDaysReveal, which the post-hydration check consumes.
  • Pending flag reset in load() alongside pendingTimelineRefresh, so scope switches/reloads start clean.
  • Loop safety: one check per hydration completion (coalesced via revealPreviousDaysScheduled), termination is condition-driven, and every cycle strictly decreases the window start index by 8 — finite by construction.
  • Manual button behavior, SSE pendingTimelineRefresh cycle, and #895 scroll-stability work unchanged; no API or MediaGrid changes.

Verification

  • Discrimination proof: with the fix stashed, both new tests fail deterministically (chain frozen at start=6, day 0 never requested); with the fix applied they pass.
  • npm run check: 0 errors (20 pre-existing warnings).
  • npm run build: success.
  • npx playwright test tests/timeline.spec.ts (desktop + Pixel 7): 79 passed, 11 skipped, 0 failed, 0 flaky.
  • New coverage in timeline newer days hydration: auto-chain to index 0 without any click (asserts all 24 days fetched incl. day 0, which only the second chained batch requests) and a "Show newer days" click landing while a batch is in flight that must be remembered and completed.
  • Adapted to #904 idioms during rebase (frame wait instead of fixed sleep in the pending-reveal test); scroll-stability and bounded-window regressions all green.
## Root cause (empirically reproduced on the unpatched build) After reloading into a restored mid-timeline window, scrolling up fired exactly one `revealPreviousDays` batch and then stalled with the "Show newer days" button still visible: 1. **One-shot IntersectionObserver**: the top sentinel observer (`rootMargin: '900px 0px'`) fires only on intersection *transitions*. After a restore places the viewport far below the sentinel, the first upward approach consumes the single transition; the sentinel then stays inside the margin, so no further callbacks ever fire. In-session axis jumps mask this because days above are already hydrated. 2. **Dropped calls while loading**: `revealPreviousDays` early-returned when `loadingVisibleDays` was true — a manual click or observer call landing during an in-flight batch was silently lost. Reproduced deterministically with a request-gated fixture: window frozen at `visibleDayStartIndex = 6`, item requests frozen at 18, sentinel still in the margin. ## Fix (apps/web/src/routes/+page.svelte, minimal) - `hydrateDays`'s `finally` (winning `loadSequence` only) now calls `schedulePreviousDaysRevealCheck()`, which after `tick()` re-evaluates the margin condition (`sentinel.getBoundingClientRect().top < innerHeight + 900`) and re-triggers `revealPreviousDays()` — a condition-driven loop that chains 8-day batches until the sentinel leaves the margin or the window reaches index 0. - `revealPreviousDays` no longer drops calls during in-flight loads: it sets `pendingPreviousDaysReveal`, which the post-hydration check consumes. - Pending flag reset in `load()` alongside `pendingTimelineRefresh`, so scope switches/reloads start clean. - Loop safety: one check per hydration completion (coalesced via `revealPreviousDaysScheduled`), termination is condition-driven, and every cycle strictly decreases the window start index by 8 — finite by construction. - Manual button behavior, SSE `pendingTimelineRefresh` cycle, and #895 scroll-stability work unchanged; no API or MediaGrid changes. ## Verification - Discrimination proof: with the fix stashed, both new tests fail deterministically (chain frozen at start=6, day 0 never requested); with the fix applied they pass. - `npm run check`: 0 errors (20 pre-existing warnings). - `npm run build`: success. - `npx playwright test tests/timeline.spec.ts` (desktop + Pixel 7): **79 passed, 11 skipped, 0 failed, 0 flaky**. - New coverage in `timeline newer days hydration`: auto-chain to index 0 without any click (asserts all 24 days fetched incl. day 0, which only the second chained batch requests) and a "Show newer days" click landing while a batch is in flight that must be remembered and completed. - Adapted to #904 idioms during rebase (frame wait instead of fixed sleep in the pending-reveal test); scroll-stability and bounded-window regressions all green.
test(web): use frame wait in newer-days pending reveal test
All checks were successful
Wiki Sync / Sync wiki from docs (push) Has been skipped
Build and Deploy / Detect changed services and test scopes (push) Successful in 3s
Build and Deploy / Android unit tests and debug APK (push) Has been skipped
Build and Deploy / Smoke API and media worker (push) Has been skipped
Build and Deploy / Smoke web (push) Has been skipped
Build and Deploy / Smoke ML worker (push) Has been skipped
Build and Deploy / Smoke people worker (push) Has been skipped
Build and Deploy / Build postgres image (push) Has been skipped
Build and Deploy / Build plants worker image (push) Has been skipped
Build and Deploy / Build converter worker image (push) Has been skipped
Build and Deploy / Deploy postgres (push) Has been skipped
Build and Deploy / Build API image (push) Has been skipped
Build and Deploy / Build media worker image (push) Has been skipped
Build and Deploy / Build people worker image (push) Has been skipped
Build and Deploy / Build web image (push) Has been skipped
Build and Deploy / Build ML worker image (push) Has been skipped
Build and Deploy / Deploy API (push) Has been skipped
Build and Deploy / Deploy web (push) Has been skipped
Build and Deploy / Deploy media worker (push) Has been skipped
Build and Deploy / Deploy ML worker (push) Has been skipped
Build and Deploy / Deploy plants worker (push) Has been skipped
Build and Deploy / Deploy people worker (push) Has been skipped
Build and Deploy / Deploy converter worker (push) Has been skipped
Build and Deploy / Clean Docker build artifacts (push) Has been skipped
Build and Deploy / Run scoped PR tests (push) Successful in 5m1s
e22dbe9470
chris merged commit a126e40245 into main 2026-09-27 12:55:50 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
chris/memories!910
No description provided.