Paginated goForward/goBackward can return true without moving the page
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
- Clearly specified
- Activity status
- Active
- Tech stack
- ios, javascript, swift
Research direction
Start with EPUBReflowableSpreadView.swift lines 218–233 and the snapOffset implementation in Scripts/src/utils.js, as named in the issue; trace how UIKit’s content offset and WebKit’s scrollX determine page moves. Reproduce with rapid consecutive navigation in a paginated EPUB and compare the positions before and after each call. Done means each call that returns true visibly changes the page without crossing into the wrong resource.
Written by the indexing model from the issue text.
Description
Describe the bug
In a paginated reflowable EPUB, goForward(options:) and goBackward(options:) can return true while the page stays where it was, or cross into the wrong resource.
EPUBReflowableSpreadView.go(to:options:) decides between scrolling inside a resource and crossing to the next one from scrollView.contentOffset.x, then scrolls with window.scrollBy in JavaScript. UIKit's offset and WebKit's scrollX are not always in step. We found two situations.
1. A move made straight after another
contentOffset trails WebKit's scroll position for a moment after scrollBy. A second goForward(options: .none) made in that gap, from the last-but-one page of a resource, computes its target from the stale offset, finds it in range, and calls scrollBy on a page that is already the last one. Nothing moves and the call returns true. Going backward from the second page of a resource, the stale offset can instead make it cross into the previous resource.
2. After entering a resource from its end
Going backward into the previous resource calls readium.scrollToPosition(1). That sets scrollLeft to the full scrollWidth, because snapOffset rounds scrollWidth + 1 down to a page boundary, which is scrollWidth itself. The view shows the last page and contentOffset.x is scrollWidth - innerWidth, but window.scrollX can go on reporting scrollWidth, one page beyond the range. We saw this hold for at least 600 ms on a second navigator kept behind the visible one: scrollX 1902, scrollWidth 1902, innerWidth 951, contentOffset.x 951.
The next goBackward computes a valid target from contentOffset, then scrollBy(-innerWidth) moves WebKit from 1902 to 951, which is where the view already is. Nothing moves and the call returns true.
How to reproduce?
- Open an EPUB whose spine items are each two or three pages long, in paginated mode. We used six generated XHTML files of about 14 short paragraphs each, at 951 x 669 points with two columns.
- Call
await navigator.goForward(options: .none)in a loop, with nothing between the calls. - Before and after each call, read
window.scrollXandreadium.link.hreffrom the visible web view.
Expected: every call that returns true shows a different page.
Actual: some calls return true with the same href and scrollX as before, mostly on the last page of a resource.
For the second case, step forward into the next resource, step back, wait for the page to settle, and compare window.scrollX with scrollView.contentOffset.x. Then call goBackward(options: .none) once more.
How often it happens depends on the device. Waiting for fonts and two stable animation frames after each move is not enough: on an iPhone 15 Pro one move in six rounds of a twelve-page book still stayed put.
Readium version
3.11.0, with a few local patches that do not touch this code. The same lines are on develop at 3b6b1559: EPUBReflowableSpreadView.swift lines 218 to 233, and snapOffset in Scripts/src/utils.js.
OS version
iOS 27.2 and 27.2.1
Testing device
iPhone 13 Pro Max and iPhone 15 Pro (physical devices)
Environment
No response
Additional context
Workarounds we use, in case they help:
- Before each move, wait until
contentOffset.xequalsscrollX. For a right-to-left document the offset to compare isscrollWidth - innerWidth + scrollX, becausescrollXcounts down from zero whilecontentOffset.xcounts up from the left edge. - When
scrollXis outside0...(scrollWidth - innerWidth), callwindow.scrollTowith the clamped value before the next move. - After each move, compare
hrefandscrollXwith the values before, and repeat a move that changed neither.
Possible fixes:
- Decide inside one script: read
scrollX, choose between scrolling and crossing, scroll, and return whether it moved. That takes UIKit's offset out of the decision. - Or wait for the two positions to agree before deciding.
- Clamp the target in
scrollToPositiontoscrollWidth - pageWidth, which removes the second case.
The comment in the source explains that scrollBy was chosen over scrollTo for right-to-left content. An absolute target would also work there: it is scrollX - innerWidth going forward.
- Dominant language
- Swift
- Stars
- 557
- Forks
- 249
- Avg merge
- 3h 52m
- Merged PRs (30d)
- 19
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from readium/swift-toolkit
-
triage
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
readium/swift-toolkit#954 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 63/100
readium/swift-toolkit#841 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 57/100
readium/swift-toolkit#961 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
readium/swift-toolkit#953 ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 Half a day Newbie friendliness 65/100
readium/swift-toolkit#948 ·
Maintainers usually reply within 1 day
All issues in readium/swift-toolkit
Similar issues
-
area: models enhancement needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
rexmhall09/TUFF#69 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
nikitabobko/AeroSpace#2427 · 1 comment ·
Maintainers usually reply within 8 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 63/100
Maintainers usually reply within 1 day
-
documentation good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
A second click on the Control Center widget doesn't close Control CenterPossibly taken @MaHofseth claimed this today. Openneeds-triage
Difficulty 2/5 1-3 hours Newbie friendliness 78/100