fix: a document opens on the page it settles on

A pagination pass measures the DOM the last one changed, so a fresh
document searched for its layout in public — 12 of them over 550ms on a
two-column file, a phantom third page among them. Two real causes: the
flow's overflow test had no headroom, so it read its own last answer
(880px fits undecorated, 913px overflows once the decoration pins the
column height), and a split dropped the height decorations without
clearing their cache key. The rest is inherent to measuring rendered
DOM, so the page stays hidden until its layout repeats: one visible
layout instead of 12, and 21-139ms where there are no columns.
This commit is contained in:
Steffen Becker committed 2026-08-12 21:50:15 +00:00
1 parent efd4e9c8a7
commit b35551acd0
5 files changed
+88 -3

No files matched your search

+8 -1
View File
@@ -201,6 +201,10 @@ export const ColumnsFlow = Extension.create({
}
function dispatchFlow(tr: Transaction): void {
// A split or join replaces the nodes the height decorations sit on, so
// ProseMirror drops them; the cache key would keep them from coming back
// and leave the fragment measuring its balanced height instead of its slot.
lastDecoKey = '';
editorView.dispatch(tr.setMeta('addToHistory', false).setMeta(FLOW_TX, true));
}
@@ -318,7 +322,10 @@ export const ColumnsFlow = Extension.create({
// are judged from the content itself (per-column share of the flow).
const usedPerColumn = contentHeightPx(children, scale) / count;
if (usedPerColumn > available + 1) {
// The estimate averages the flow over the columns, but each column ends on
// a whole line, so a fragment measuring exactly its slot still spills once
// the decoration pins the height — split with the budget's own headroom.
if (usedPerColumn > available - SAFETY_PX) {
// Overflow. Same first-block fit test (incl. margin) as pageBreaks'
// push decision — the two must agree, or split/push/join cycle.
const first = Math.max(blockHeightPx(children[0], scale) / count, MIN_BLOCK_PX);