Proposal
readest/readest #6873 · plan · pinned readest 5273f82, foliate-js 50435d7 · inline-style breaks fixed in #6888 (merged, unreleased)
Two-page mode: start a section on a new spread when its spine entry says so
Proposal: when a section's spine entry declares page-spread-left (page-spread-right in right-to-left books) and the columns before it are odd, the previous section gets one blank column, so the declared section opens a new spread. Undeclared sections keep packing (“so no half-empty spreads appear”, 2026-10-17); the spine is where that reply said a new spread should be specified.
Approach
One rule in the foliate-js paginator, active only in paginated mode at exactly two horizontal columns: before the first chunk of a declared section, add the blank column when the columns before it are odd; re-check whenever a view is added, removed or re-measured. Ships as a readest/foliate-js PR plus a readest PR (submodule bump and browser test). Biggest risk the change adds Books whose spine already declares page-spread-left (EPUB, and AZW3 through its KF8 spine record) change layout: each declared section that would start mid-spread gets a blank column first, where today the spread is packed. How many reflowable books declare it is unknown. Mitigation Before merge, count affected books on the maintainer's EPUB and AZW3 corpus and confirm layout changes only there, as #6888 did for its rewrite. Control tests pin the rest: undeclared sections still pack, and 1 or 3 columns, scrolled and vertical modes are untouched. Open questions (maintainer)
- Also offer an opt-in “start each chapter on a new spread” reader setting (upstream foliate-js's layout, and Readest's before 0.10.1)? Yes: a separate small PR rounds every section up to whole spreads while the setting is on, plus one settings row and its strings. No: the spine declaration is the supported route, and the issue reply can point authors to it.
- Should in-file
page-break-before: left|right, which today does not break at all, become at least a column break, in its own PR? Yes: a small rewrite fix with its own test. No: in-file breaks stay column breaks as described in the thread.
Same book, two columns, left-to-right. Green: Ch.2, whose spine entry declares page-spread-left. Blue: Ch.3, which declares nothing. From source, not run: today, opening the book at Ch.2 (Ch.1 not loaded) puts it in the left column instead (fact 5), so its start depends on how the reader got there; proposed, it starts on the left either way.
Beyond the issue
- The spine flag the thread points to is parsed and then ignored for reflowable books: epub.js turns
page-spread-left|rightintopageSpread; in foliate-js only fixed-layout.js reads it, the reflowable paginator never does. A book that follows the thread's advice still lands in the next free column. - Until 0.10.1 Readest's two-page mode started every section on a new spread (old sizing). Per-column sizing came with #3546, which closed #3419: two image sections shown side by side. Reverting the default would undo #3419.
- EPUB 3.3 §8.2.2.4 makes today's packing the default (“the next EPUB content document in the next available unpopulated viewport”) and applies
page-spread-*to reflowable content too. Spec-backed answer for the reporter. - #6888 is on
mainbut in no release: v0.12.16 (Oct 13), which the reporter runs, predates it. Whatever the reporter opened on Oct 22 lacked the inline-break fix, unless built from source. - From source, not run: spreads count from the first loaded section (paginator.js). A chapter whose previous chapter is not loaded (book opened there, or a jump that unloads it, paginator.js) starts on the left; one reached by paging, or with its previous chapter still loaded, follows that chapter. Tests cover both paths.
Contributor guide
Who: any contributor; outside PRs land in the fork (readest/foliate-js#131). Confirm on the issue before opening a PR, per CONTRIBUTING.md. Question 1 is a separate PR and only on a yes: “one PR, one goal” (acceptance.md).
Files, in order
- readest/foliate-js
paginator.js,View.expand()(per-column sizing): let a view carry a count of trailing blank columns (0 or 1) and add it to the element's width only. Content pages (contentPages), which feed progress, stay content-only. - readest/foliate-js
paginator.js, the paginator: one pass over the views in order. A view is declared when it is chunk 0 (#units[i].chunk === 0; chunks copy the whole section, here) and itspageSpreadis the first slot (left, orrightin a right-to-left book).pageSpreadcomes from the EPUB spine, aliases included (epub.js), and from the KF8 spine record of AZW3 books (mobi.js). Before a declared view whose preceding columns are odd, the previous view gets one trailing column; every other view gets 0. Run the pass only when not scrolled, not vertical andcolumnCount === 2(otherwise clear all to 0), after a view is inserted or removed and after any view re-expands; when a blank count changed, re-anchor the primary view, sinceonExpandre-anchors only when the primary itself expands (paginator.js). - readest: bump
packages/foliate-jsand addapps/readest-app/src/__tests__/document/paginator-spread-start.browser.test.ts(new), built on the synthetic-book harness in paginator-page-progression-direction.browser.test.ts at 800×600 withmax-column-count2. Same shape as readest #6889 (submodule bump plus browser test).
Requirement → change → test (all proposed)
“Position” means the on-screen x of the section's first element (iframe rect plus element rect): left or right half of the 800 px paginator. Sections are synthetic objects carrying pageSpread, so one test covers EPUB and AZW3 alike. Each test first asserts its precondition (Ch.1 ends on a left column), so it cannot pass vacuously.
| # | Requirement | Test | Today |
|---|---|---|---|
| R1 | Left-to-right, paged forward: a section declaring page-spread-left opens in the left column. | open at Ch.1, page to Ch.2's first page; position is left | fails (right) |
| R2 | Same when Ch.2 is opened directly and the reader pages back into Ch.1. | goTo(Ch.2), prev(): Ch.2 not visible on that spread; next(): position is left | fails (shares spread) |
| R3 | Right-to-left book: page-spread-right opens a new spread (right column). | R1 with dir: 'rtl' and pageSpread: 'right'; position is right | fails (left) |
| R4 | Undeclared sections keep packing. | R1 without the property; position is right | control passes |
| R5 | Only two horizontal paginated columns are affected. | R1 at max-column-count 1; at max-column-count 3 with max-inline-size 266px (assert columnCount === 3 first); in flow="scrolled"; and with vertical-rl sections on an 800×1000 host (assert columnCount === 2 first): Ch.2 follows Ch.1 with no blank column | control passes |
| R6 | A chunked declared section starts a spread once, at chunk 0. | declared section over 512 KiB (chunk harness in paginator-chunked-section.browser.test.ts); precondition: chunk 0 ends on a left column. Chunk 1 follows chunk 0 with no blank column | guard passes; fails if keyed on the section |
| R7 | Re-measure keeps the rule: when Ch.1's column count turns even, the blank column goes away. | R1, then restyle Ch.1 (font size) until its column count is even: Ch.2 still left, and no spread has both columns blank. Also restyle only Ch.1 while Ch.2 is primary: Ch.2's first page stays on screen, in the left column | fails on the odd step |
| R8 | Second-slot declarations stay as today (scope). | Ch.2 with pageSpread: 'right' in a left-to-right book: same position as R4 | control passes |
Commands (from AGENTS.md, run in apps/readest-app)
pnpm test:browser src/__tests__/document/paginator-spread-start.browser.test.ts # inner loop
pnpm test:browser # CI: test_web_app, shard 1 (.github/workflows/pull-request.yml:268)
pnpm test # unit suite
pnpm lint # Biome + tsc
Exit criteria
- R1–R8 in place. R1–R3 and R7 fail on
mainwithout the foliate-js change, on an assertion naming the column, and pass with it; that run is recorded in the commit body (acceptance.md). pnpm test,pnpm lintandpnpm test:browserpass on the change merged onto currentmain.- Corpus count: how many reflowable books declare
page-spread-*, and layout changes in no other book (the risk mitigation). - Real use on the reporter's surface: Linux desktop, a book whose spine declares
page-spread-left(the reporter's sample if it declares it, else a copy with that property added to its spine). Not on Linux: say so. - The commit credits “Reported by openlayers0 on GitHub”.
Implementation notes
Options considered
| Option | What it does | Cost and consequence |
|---|---|---|
| A. Honour first-slot declarations (recommended) | Declared section opens a new spread; everything else packs. | One paginator rule plus tests. Matches the thread's direction and EPUB 3.3. Helps the reporter only if their book declares it, or once they add it (U1). |
| A2. Also honour second-slot declarations | page-spread-right in a left-to-right book puts the section in the right column, adding a leading blank column when needed. | When the section is the first loaded view, the blank column has to sit inside its own view, which shifts the offset and progress math that assumes content starts at the view's edge. Defer until a book needs it (R8 pins today's behaviour). |
| B. Opt-in reader setting (question 1) | Round every section up to whole spreads while on. | Small sizing change; adds a settings row and strings. Needs no book edits, but not a default: acceptance.md leaves layout decisions to the maintainer. |
| C. Revert the default to whole-spread sections | Upstream foliate-js behaviour (upstream). | Out: reverses the layout chosen in #3546 and restated on 2026-10-17, and undoes #3419. |
D. In-file break-before: left|right (question 2) | At least a column break. | Separate PR. Landing on the requested side needs layout measurement inside the document; a plain column break does not. |
Inputs × consumers of the change (a trailing blank column on the view before a declared section)
| Consumer | Effect | Source |
|---|---|---|
| View offsets, spreads before a view | Declared view now starts on a spread boundary: the intended effect. | paginator.js |
pages of the previous section | round(viewSize / size): unchanged when the previous view has an odd count; one more when an even-count view that starts in a right column gets the blank. No host code reads renderer.pages. | paginator.js |
| Progress fraction | Uses content pages, not the element width: unchanged. | paginator.js |
| Page backgrounds | Painted per view, so the blank column takes the previous section's background. | paginator.js |
| Chunked sections (over 512 KiB) | Every chunk carries the section's properties, so the rule keys on chunk 0 (R6). | paginator.js |
| AZW3 (KF8) books | Their spine record's page-spread-* also lands in pageSpread, so the rule applies to them the same way; counted in the corpus check. | mobi.js |
Apple/Kobo open-to-spread=false | Sets the second slot on the first section (right, or left in right-to-left books), which this rule does not act on. | epub.js |
| “Separate Cover Page” | Writes pageSpread for pre-paginated books only, so it never reaches this rule. | FoliateViewer.tsx |
| 1, 3 or 4 columns; scrolled; vertical | No-op (R5). Columns range 1–4 (LayoutPanel.tsx); a two-page spread exists only at 2. | paginator.js |
| Paths that re-lay out views | Append, prepend on paging back, trimming distant views, font load or resize re-expand, column-count change: each re-runs the pass (R2, R7). | paginator.js, paginator.js |
All facts
- Per-column sizing and its stated purpose: paginator.js, from foliate-js commit
e925e9d9(2026-03-17); first readest release carrying it is v0.10.1 (2026-03-22), v0.9.101 does not (submodule pins of the tags). - The thread's reply that a new file “continues on the same spread” is this sizing. The short-section rule loads the previous section to fill the leading columns: paginator.js.
- The spine properties also reach each section's root element as
data-*attributes, unused for placement: paginator.js. - Upstream foliate-js (used by Foliate) sizes sections in whole spreads (upstream) and turns page breaks into column breaks just as Readest does (upstream; Readest: paginator.js). Foliate 3.3.0 (2025-04-01, its latest release) ships foliate-js
052123be, which does the same (sizing, breaks). From source, not run: in-file breaks go to the next column in both; the difference the reporter sees is per-section sizing. - #6888 notes that
page-break-before: left|rightand a lonebreak-before: alwaysstill do not break; its rewrite keeps the value (style.ts). - No setting restores per-spread starts in paginated mode: “no continuous scroll” applies only when scrolled (paginator.js).
- Fixed layout already applies the slot rules, mirrored for right-to-left (fixed-layout.js).
- Paging past the first loaded section goes to the previous unit (paginator.js).
- CI runs browser tests in
test_web_appshard 1 (pull-request.yml); the existing two-column block is paginator-paginated.browser.test.ts.
Unknowns
| Unknown | Blocks | Closes it |
|---|---|---|
U1. Does the reporter's sample declare page-spread-* in its spine? (The sample was not downloaded.) | Whether option A alone fixes their book, or they add properties="page-spread-left" to the itemrefs. | The maintainer, who has the sample: search its OPF for page-spread. |
| U2. How many reflowable books declare it. | Size of the layout change (the risk). | The maintainer's EPUB and AZW3 corpus, as used for #6888. |
Not in this change
Changing the default; second-slot placement (A2); page-spread-center; vertical writing (its multi-column layout was not traced); in-file left/right breaks (question 2); the release that ships #6888.

