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

+6
View File
@@ -128,6 +128,9 @@
let pageFormat: PageFormat = $state(loadPageFormat());
let tabIntervalCm = $state(loadTabInterval());
let spacingModel: SpacingModel = $state(loadSpacingModel());
// Bumped for each document opened (import, new); Editor hides the page until that
// document's pagination holds still.
let documentEpoch = $state(0);
// The document's spell-check language; round-trips through the .odt. The effect
// below persists it and switches the shared spell controller (loads the dict).
@@ -447,6 +450,7 @@
if (!editor) return;
if (isDocNonEmpty() && !confirm(t().dialogs.confirmNew)) return;
editor.commands.setContent('<p></p>'); // onUpdate fires → autosave
documentEpoch++;
resetHistory();
// Reset everything to defaults; the $effects persist these.
hfActive = null;
@@ -511,6 +515,7 @@
void saveEmbeddedFonts(result.fonts);
editor.commands.setContent(result.content); // onUpdate fires → autosave
documentEpoch++;
resetHistory();
// Adopt the opened file's name as the document name (drives the save filename).
if (sourceName) documentName = stripOdtExtension(sourceName).replace(/\.docx$/i, '');
@@ -1098,6 +1103,7 @@
onchange={handleImportFile}
/>
<EditorComponent
{documentEpoch}
bind:editor
bind:tick
bind:currentPage