fix(paginator): tolerate not-yet-loaded section documents in early resize renders

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.
This commit is contained in:
John O'Keefe committed 2026-10-02 15:17:00 -04:00
1 parent 8e1d5fc8d6
commit 50f56ee67f
2 files changed
+5 -1

No files matched your search

+1 -1
View File
@@ -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",
+4
View File
@@ -220,6 +220,8 @@ const makeMarginals = (length, part) => Array.from({ length }, () => {
})
const setStylesImportant = (el, styles) => {
// some generated section documents have no <body>/<html>
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)