From 50f56ee67ff4803c4d0d1c287dd5d89dccbb577a Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Fri, 2 Oct 2026 15:15:47 -0400 Subject: [PATCH] fix(paginator): tolerate not-yet-loaded section documents in early resize renders MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The ResizeObserver can fire while the iframe document is still unset: setImageSize dereferenced doc.body unconditionally and setStylesImportant destructure-crashed on null, killing the render loop — the view then never snapped or relocated again (observed in an embedded Android WebView where the first observation lands pre-load). Guard both paths. --- package.json | 2 +- paginator.js | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 44f1405..3212e14 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "foliate-js", - "version": "0.3.0", + "version": "0.3.1", "description": "Render e-books in the browser", "repository": { "type": "git", diff --git a/paginator.js b/paginator.js index 63364f9..4149be8 100644 --- a/paginator.js +++ b/paginator.js @@ -220,6 +220,8 @@ const makeMarginals = (length, part) => Array.from({ length }, () => { }) const setStylesImportant = (el, styles) => { + // some generated section documents have no / + if (!el) return const { style } = el for (const [k, v] of Object.entries(styles)) style.setProperty(k, v, 'important') } @@ -359,6 +361,8 @@ class View { const { width, height, margin } = this.#layout const vertical = this.#vertical const doc = this.document + // the iframe document may not be loaded yet on early resize renders + if (!doc?.body) return for (const el of doc.body.querySelectorAll('img, svg, video')) { // preserve max size if they are already set const { maxHeight, maxWidth } = doc.defaultView.getComputedStyle(el)