[Bug]: EPUB reader loses TOC heading anchors and mislabels reading positions
Do you need to file an issue?
- I have searched the existing issues and did not find an issue covering these specific defects.
- I believe this is a legitimate bug.
Describe the bug
In the EPUB reader, nested TOC entries lose their individual heading targets, while the sidebar and header expose internal spine positions using inconsistent page/chapter terminology.
- Nested TOC navigation: a chapter and its subsections can all share one numeric locator. Clicking a subsection navigates to the chapter file, rather than its heading. Within that chapter, clicking another subsection appears ineffective because the target is still the same file.
- Sidebar position labels: multiple entries repeat the same numeric locator and use a “page” tooltip. This number is a spine reading-unit index, not a rendered page number.
- Header position labels: the header displays “Chapter N / total” from the locator and unit count. Front matter such as title and contents pages can be included in that count. The number also remains unchanged while turning multiple rendered pages within the same chapter. Being in the final spine item does not mean the reader has reached the end of the book.
The original EPUB inspected during diagnosis contains distinct, valid heading anchors. This is a navigation/display problem, not evidence of missing source content or lost pagination.
Steps to reproduce
Use a generic EPUB with:
- a title page and a contents page included in the spine;
- chapter A containing two headings, A1 and A2, separated by enough text to require multiple rendered pages;
- chapter B also spanning multiple rendered pages;
- nested TOC links with distinct fragments, for example:
<a href="text/chapter-a.xhtml#chapter-a">Chapter A</a>
<a href="text/chapter-a.xhtml#section-a1">Section A1</a>
<a href="text/chapter-a.xhtml#section-a2">Section A2</a>
<a href="text/chapter-b.xhtml#chapter-b">Chapter B</a>Each referenced ID should exist in its target XHTML.
- Import the EPUB and open it in Immersive Reading.
- From chapter B, click A2 in the sidebar: it targets the chapter file instead of A2.
- Within chapter A, click A1 and A2 in succession: the distinct heading targets are not honored.
- Inspect the repeated sidebar numbers and page tooltips.
- Turn several pages within the final chapter: the header remains at the final numeric chapter position even before the final rendered page.
This generic fixture specification is intended for regression coverage; a synthetic EPUB browser reproduction has not been run for this report. The reported behavior comes from user-provided UI evidence, with archive, stored-outline, and frozen-source inspection supporting the diagnosis. No private publication or workspace URL is needed.
Expected Behavior
- Preserve each TOC entry's file path and heading fragment through extraction, storage/API, and navigation, including jumps within the current chapter.
- Prefer TOC titles and hierarchy; remove the internal numeric column and misleading page tooltip, or use an explicitly accurate alternative.
- Prefer the current chapter title plus meaningful whole-book progress in the header. Do not label spine-file counts, including front matter, as semantic chapter counts or rendered page counts.
- Handle already-imported EPUBs as well as new imports; the recovery approach can be determined by maintainers.
Acceptance criteria using the generic fixture above:
- Cross-chapter and same-chapter clicks on A1/A2 land at their respective headings.
- TOC order, nesting, and collapse/expand behavior are preserved.
- Title/contents pages are not presented as content chapters.
- Sidebar and header terminology accurately distinguishes chapter, rendered page, and reading progress.
- Entering the last spine item does not itself imply completion; if a percentage is shown, it reflects position within the book.
- Existing EPUB imports can benefit from the fix; PDF and Markdown navigation do not regress.
Related Module
Frontend/Web; Immersive Reading EPUB extraction and outline data.
Additional Information
- Reported version: v1.6.12.
- Source baseline:
ef2d9e5c3c99fd073742c5aadc2bb9584b1e503b. - Source inspected on 2026-09-30; behavior on later versions has not been verified.
Relevant source at that baseline:
- EPUB navigation extraction maps links to spine positions without retaining individual fragment targets in outline items.
- Reading outline construction retains locator/title/level.
- Sidebar navigation passes only the locator and labels it as a page.
- EPUB jump handling opens the spine file; a separate heading-jump path already exists at lines 512–525.
- Header counter displays current locator / unit count.
Related: #987 (outline navigation), #1447 (reading workspace enhancements). This report focuses on per-entry EPUB fragments and position-label semantics, rather than active-locator tracking or layout controls.
Source: HKUDS/DeepTutor