EPUB: a Decoration built per occurrence of a repeated phrase collapses onto one earlier occurrence

Open
#873 2 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
javascript
Domain
mobile

Research direction

Start by reading the vendored TextQuoteAnchor implementation and the rangeFromLocator body in Scripts/src/utils.js, then reproduce the eight-identical-refrain case described in the issue. Done means each of the eight locators resolves to its own range and each occurrence is highlighted once, rather than several resolving to the same earlier range.

Written by the indexing model from the issue text.

Description

Describe the bug

When one block repeats the same phrase with identical surrounding text (a verse refrain), building a Decoration/highlight per occurrence collapses several of them onto a single earlier occurrence — some occurrences get highlighted more than once, others never.

Expected: each occurrence resolves to its own range and is highlighted once.

How to reproduce?

Deterministic, reproduced directly against Readium's own vendored anchoring (TextQuoteAnchor + the rangeFromLocator body from Scripts/src/utils.js, 3.8.0):

  1. Take one block that repeats a phrase with identical context, e.g. eight lines of the tide will turn,.
  2. For each occurrence, build its TextQuoteSelector the way a client does from a selection (TextQuoteAnchor.fromRange, 32-char prefix/suffix), then resolve it back with rangeFromLocator.
  3. Occurrences whose ±32-char context is identical all resolve to the same earlier range. In the fixture below: 8 locators → 5 distinct ranges; #4–#6 all land on #3.

Any client that decorates each occurrence (annotations, search highlights) goes through the same rangeFromLocator, so the collapse is not specific to the harness. I have a self-contained HTML harness (opens in any browser, no build) plus a screenshot of the result and will attach them here shortly.

Readium version

3.8.0

OS version

N/A — the bug is in the injected JS anchoring layer, independent of iOS version.

Testing device

N/A — JS layer (repro run against the vendored anchoring in a browser and under Node/JSDOM).

Environment
macOS: 15.7.4
platform: arm64
Xcode 26.3
Build version 17C529
Additional context

Widening the fixed ±32-char context window does not help — a longer identical refrain defeats any fixed length. Previously raised as #860 (closed with a request to re-file per the template).

Dominant language
Swift
Stars
557
Forks
249
Avg merge
3h 52m
Merged PRs (30d)
19

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from readium/swift-toolkit

All issues in readium/swift-toolkit

Similar issues

More Swift issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.