Repository navigation
fix(web): complete audiobook locator fields after go() - #368
ddfreiling wants to merge 4 commits into
Conversation
Upstream AudioNavigator.go() makes the caller's locator the current one, and position polling copies it forward. A restored position or ToC jump has no title, so every later web audio locator had title null, and apps that validate bookmarks dropped them. tocHref was never set either: the plugin resolved timelineItemChanged items from pub.timeline against a separately built Timeline, so the lookup always missed. Plain audiobook locators now get title and tocHref from the ToC entry playing at the current time (last timed entry for the track at or before t), falling back to the reading-order track title. This mirrors the iOS timebased enrichment. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
During stream recovery, plain audiobooks pinned the "loading" state with the raw navigator locator, so it lacked title, tocHref and totalProgression. Route it through emit(), as Media Overlay already did. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Upstream go() keeps the caller's locations. A locator built from a ToC link has no t= fragment and no progression, and while paused no position poll replaces it, so a chapter skip followed by a bookmark emitted progression null. LYT4 rejects such bookmarks. Fill a missing t= fragment from playback and a missing progression from the time and track duration, as iOS and Android always emit both. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
m-abs
left a comment
There was a problem hiding this comment.
Reviewed the diff plus the flow it touches, and ran the web gates against this branch in a throwaway worktree.
What this change does: On web, every plain-audiobook locator now gets its title and locations.tocHref filled in from the table-of-contents entry playing at the locator's time, the same lookup iOS does. The old Timeline-based tracking is deleted (it never worked), and the recovery "loading"/"failure" state now goes through the same fill-in as every other state.
Verified on this head: tsc clean, eslint clean, full Jest suite 546/546 pass, production rollup bundle builds. The 4 new tests do fail on main, so they really pin the bug. Both cause claims check out against upstream source: AudioNavigator.go() sets currentLocation = locator.copyWithLocations(...) (keeps the caller's missing title forever), and Timeline.build() makes its own item objects, so the old timeline.linkFor(item) lookup on navigator-supplied items missed by identity — tocHref really was always undefined. createLocator() uses the manifest-relative href plus a t= fragment, so the new lookup matches real locators, not just the test fake.
Load assumed: one reader in one browser tab, state emitted once per poll interval. Nothing here scales badly.
Should fix
1. The same broken bookmark still ships from one call site over (flutter_readium/web/src/ReadiumReader.ts:438-449)
- What this is: When you jump to a locator (ToC tap, restored position) and no audio navigator is live,
goToremembers the locator and tells Flutter about it. - Problem: That report hand-builds its JSON instead of going through the fill-in path, so it carries no
title, notocHrefand nototalProgression. This is reachable:stop()(ReadiumReader.ts:1110-1133) destroys the audio navigator but keeps the publication open. Tap a chapter after that and the app gets an untitled locator — exactly the symptom this PR set out to kill — and may store it as a bookmark. - Fix: Lift the closure body at
FlutterAudioNavigator.ts:797-806into an exportedmakeAudioChapterEnricher(publication)(it only needs the publication and the flattened ToC), use it increate()and wrapaudioLocatorwith it beforeserialize()here. About 3 net lines, no new concepts. - If we skip it: Say so in the PR description as a known remaining gap. Silent is the bad outcome.
2. Audiobooks whose ToC points at bare files still get no title (flutter_readium/web/src/navigators/locatorEnrich.ts:90-108)
- What this is: The lookup only accepts ToC entries whose href carries a
#t=start time. - Problem: A common audiobook shape is one file per chapter with ToC entries like
track1.mp3and no time fragment. Every entry is then skipped, sotocHrefstays unset and the title falls back to the reading-order link's title — often absent for those manifests, so the locator still reaches Dart with notitleand the reported bug survives for that publication shape. - Fix: When the timed lookup finds nothing, fall back to the first ToC entry for the same file.
locatorEnrich.tsalready has that infindCurrentTocHref(used by EPUB and TTS); reuse it for bothtocHrefand the title. Two lines. - If we skip it: It is a deliberate parity call — iOS does the same (
FlutterReadiumPlugin.swift:992-1012, and its second fallback needs acssSelectoraudio locators never have). Then keep it, but the changelog line "audiobook locators now carry the chapter title" reads as a promise for those books. My recommendation: add the fallback on web, file the iOS/Android gap separately.
3. Two near-copies of the same locator-copy code (FlutterAudioNavigator.ts:173-190 vs locatorEnrich.ts:62-83)
- What this is:
withTocHrefandenrichWithTocHrefboth rebuild aLocatorand setotherLocations.tocHref, field by field. - Problem: This PR makes the audio path depend on the copy in the navigator file while EPUB and TTS use the one in
locatorEnrich.ts. They already differ: thelocatorEnrichone skips the work when the value is unchanged, the navigator one rebuilds a Map on every poll. Any future change to howtocHrefis carried has to be made twice. - Fix: Keep one in
locatorEnrich.ts, haveenrichWithTocHrefcall it, import it in the audio navigator, dropwithTocHrefand its__testing__entry (the 5 unit tests inFlutterAudioNavigator.test.ts:365-399move with it). - If we skip it: Nothing breaks today; it is duplication that must be edited in step later.
Nice to have
4. The ToC href match is a raw string compare (locatorEnrich.ts:99)
- Problem: A ToC entry written as
./track1.mp3#t=300, or percent-encoded differently from the reading-order href, matches nothing and the enrichment silently no-ops. iOS compares paths ($0.hrefPath == timeLocator.href.path), and this repo already has a tolerant matcher —findLinkByHref(utils/ReadiumExtensions.ts:32-48) — which the title fallback two lines away uses. - Fix: Compare pathnames the same way in both branches, or reuse
findLinkByHrefon the ToC list. Low impact, but the inconsistency is confusing to read.
5. timelineItemChanged: () => {} is now an empty listener (FlutterAudioNavigator.ts:1035)
- What this is: Upstream treats every listener as optional (
listeners.timelineItemChanged ?? (() => {})), so the no-op exists only to satisfy the plugin's ownAudioNavigatorListenersannotation. - Fix: Delete it and the six sibling no-ops by typing
listenersasPartial<AudioNavigatorListeners>. Roughly -7 lines. Fine to leave, since the file already does this for other events.
Checked and good
- Removing
Timelineis a real deletion of broken code, not a rewrite: the old lookup could never match, and nothing tested the wiring — which is why the helper had 5 passing unit tests while the feature never worked. The new test drivescreate()end to end instead. - The pinned-state change deletes a special case and routes everything through one chokepoint. Its guards (
!nav || isDisposed()) are equivalent to what it replaced, so post-close stragglers stay suppressed. - Routing every plain emission through
new Locator({...locator, title})loses nothing:Locator's fields are all own properties (upstream itself copies locators withnew Locator({...locator, ...})), andLocatorLocations' five fields are preserved by both copy helpers. - Reusing
getTimerather than hand-parsing#t=is right — it matches iOS on clock formats (1:02:03) and ranges. - Media Overlay sessions keep their own ToC source and are untouched.
Verdict: ship after 1 (or state it as a follow-up in the description), and decide 2 on purpose.
Lean: -25 lines possible.
Not checked: bin/changelog check (needs uv/pipx, not installed here — the fragment name and type match the documented pattern), bin/update_web_example's example copy (I built the bundle with --skip-example-copy), and the LYT4 web audiobook journey, which the description already flags.
Review follow-ups for the audiobook locator fill-in: - goTo on a stopped audiobook now reports the same title, tocHref, time and progression as a live navigator. The fill-in moves into makePlainAudioLocatorEnricher so both paths share it. - A ToC with one entry per file and no t= start now supplies the chapter title and tocHref instead of falling back to the track title. - ToC hrefs are matched by resolved path, so ./track.mp3 and percent-encoding variants match. - withTocHref has one home in locatorEnrich.ts, shared with EPUB/TTS. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks. All addressed in 085b8b6 except 5:
🤖 Addressed by Claude Code |
Web TTS states and EPUB text locators took their title from the positions list, whose entries have none in practice, so apps got no chapter title. iOS and Android set it from the ToC entry, as does swift-toolkit's EPUB navigator. enrichWithTocHref becomes enrichWithToc, built on a shared withTocLink(locator, link) that sets both tocHref and the entry's title, keeping the locator's own title when the entry has none. The positions title stays a fallback for TTS. The audiobook ToC lookup in Notalib#368 can reuse withTocLink. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Heads-up from #376: it renames |
A ToC entry's title is optional in RWPM. The plugin assigned it to the locator unconditionally, so an untitled entry replaced the title that the toolkit had already set with nil/null. Keep the existing title in that case. tocHref handling is unchanged. Native counterpart of #368 and #376. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Summary
On web, plain audiobook locators lose their
titleafter a jump to a locator (a ToC jump or a restored position). Apps that validate bookmarks then drop them. iOS and Android emit a title in the same flow.Cause: upstream
AudioNavigator.go()makes the caller's locator the current one, and position polling copies it forward, so an untitled locator stays untitled.tocHrefwas never emitted on web audio either: the plugin looked uptimelineItemChangeditems (frompub.timeline) in a separately builtTimeline, so the lookup always missed.Change
titleandlocations.tocHreffrom the ToC entry playing at the current time, the last#t=entry for the track at or beforet(the iOScurrentTocLinkFromTimeLocatorlookup). If no timed entry matches, the file's first ToC entry is used (one entry per file, no#t=), then the reading-order track title. ToC hrefs are matched by resolved path. The broken timeline tracking is removed.go()without at=fragment orprogression(for example one built from a ToC link during a chapter skip while paused) now gets them from playback. Before, no position poll ran while paused, so the emitted locator had neither.goTowhile the audiobook is stopped (afterstop()) now reports the same filled-in locator. All paths sharemakePlainAudioLocatorEnricher.title,tocHrefortotalProgression.Review notes
#t=; iOS and Android skip such entries, so for those books web now has a ToC title where native has the track title.Verification
FlutterAudioNavigatorLocatorTitle.test.tsdrivescreate()with a fake upstream navigator that behaves likego(). Its title and time tests each fail before their fix.FlutterAudioNavigatorTrackFailures.test.tsand stopped-goTotest inReadiumReader.test.tsfail without their fix.bin/typecheck, full Jest suite (551 tests),bin/update_web_example,bin/changelog check.bf336bc0: two ToC jumps and a paused chapter skip, both bookmarks validated.Not covered
timelineItemChangedand the other no-op listeners stay: theAudioNavigatorconstructor requires a fullAudioNavigatorListeners.