Skip to content

Defer currentLocation updates while the app is inactive - #6

Draft
raphi011 wants to merge 2 commits into
developfrom
fix/epub-defer-location-while-inactive
Draft

Defer currentLocation updates while the app is inactive#6
raphi011 wants to merge 2 commits into
developfrom
fix/epub-defer-location-while-inactive

Conversation

@raphi011

@raphi011 raphi011 commented Jul 2, 2026

Copy link
Copy Markdown
Owner

Upstream ticket: readium#841 (maintainers asked for a ticket to agree on the design before an upstream PR — this draft is the reference implementation).

Follow-ups from the corrected analysis of readium#839 (see also the closed spike #5 — its premise was falsified; the drift was app-side).

Changes

1. EPUBNavigatorViewController no longer adopts currentLocation while the app is inactive.

While the app is backgrounded, iOS renders the app switcher snapshots (running appearance/layout passes for both color schemes) and WebKit may reload or re-lay out the web views. A location computed in that window can reflect a transient scroll position the user never saw; adopting it overwrites currentLocation and misleads any observer persisting the reading progression — the restore family (readium#645, readium#321, readium#309).

The fix gates the debounced updateCurrentLocation on the existing isActive flag, symmetric to needsReloadSpreadsOnActive. Deferred, not dropped: execute(when:) polls until the app is active again and then computes the location once, against the settled layout.

2. Documented the page-start bias of restoring firstVisibleElementLocator().

go(to:) on the captured locator lands on the page on which that element begins — one page back whenever the visible page starts mid-element (e.g. mid-paragraph in a paginated reflowable publication). The protocol doc now spells out when to prefer it (page grid changed) vs currentLocation (layout unchanged).

Testing

  • Full package suite on iOS Simulator: xcodebuild test -scheme Readium-Package — 101 tests, 28 suites, green.
  • The lifecycle path has no unit harness (same as needsReloadSpreadsOnActive).
  • Host-app pass: a reader app pinning this fix (cherry-picked onto its integration branch) runs its full suite green, and the reader smoke passes — open at persisted position, background→foreground stays on page, page turns work.

Draft: intended to iterate here first, then propose upstream once readium#841 settles the design.

🤖 Generated with Claude Code

raphi011 and others added 2 commits July 2, 2026 14:41
While the app is backgrounded, iOS renders the app switcher snapshots
(running appearance/layout passes for both color schemes) and WebKit may
reload or re-lay out the web views. A location computed in that window
can reflect a transient scroll position the user never saw; adopting it
overwrites currentLocation and misleads any observer persisting the
reading progression (the restore family: readium#645, readium#321, readium#309, readium#839).

Gate the debounced updateCurrentLocation on the existing isActive flag,
symmetric to needsReloadSpreadsOnActive: the pending update is deferred
(not dropped) by the execute(when:) predicate and runs once the app
becomes active again, against the settled layout.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…leElementLocator()

go(to:) on the captured locator lands on the page where that element
begins — one page back whenever the visible page starts mid-element
(e.g. mid-paragraph in a paginated reflowable publication). Spell this
out on the protocol so users of the capture-and-restore idiom pick the
right anchor: firstVisibleElementLocator() when the page grid changed,
currentLocation when the layout is unchanged.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@raphi011

raphi011 commented Jul 2, 2026

Copy link
Copy Markdown
Owner Author

Host-app pass done: Kios now pins this branch content (the fix commit cherry-picked onto its integration branch as aca293e03). Full app test suite green against the new pin, and the reader smoke passes on the iOS Simulator — open at persisted position, background→foreground stays on the same page, edge-tap page turn works. The remaining verification item from the description is covered.

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.

1 participant