Skip to content

Commit 69abc22

Browse files
committed
fix(server): include shadow-root images when settling a resized page
document.images skips open shadow roots, so a web component's responsive image could still report its previous source after a resize.
1 parent 0c1002a commit 69abc22

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

‎apps/server/src/htmlRender/headlessChrome.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,9 @@ const consoleMessageFromEvent = (method: string, params: unknown): ConsoleMessag
147147
// Wait for fonts and two paint frames to capture late layout.
148148
const SETTLE_EXPRESSION =
149149
"document.fonts.ready.then(() => new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(() => resolve(true)))))";
150-
// A resize can select another responsive image, which a fresh load would wait for.
151-
// Poll `complete`: a dropped pending request fires neither load nor error.
152-
const RESIZE_SETTLE_EXPRESSION = `new Promise((resolve) => requestAnimationFrame(function wait() { if ([...document.images].every((image) => image.complete || image.loading === "lazy")) resolve(); else requestAnimationFrame(wait); })).then(() => ${SETTLE_EXPRESSION})`;
150+
// A resize can select another responsive image, which a fresh load would wait for. Search open
151+
// shadow roots too, and poll `complete`: a dropped pending request fires neither load nor error.
152+
const RESIZE_SETTLE_EXPRESSION = `new Promise((resolve) => requestAnimationFrame(() => { const images = []; const collect = (root) => { for (const element of root.querySelectorAll("*")) { if (element instanceof HTMLImageElement && element.loading !== "lazy") images.push(element); if (element.shadowRoot) collect(element.shadowRoot); } }; collect(document); (function wait() { if (images.every((image) => image.complete)) resolve(); else requestAnimationFrame(wait); })(); })).then(() => ${SETTLE_EXPRESSION})`;
153153
// scrollHeight is at least viewport height; use the root box for shorter pages.
154154
const MEASURE_EXPRESSION =
155155
"(() => { const root = document.documentElement; return root.scrollHeight > root.clientHeight ? root.scrollHeight : root.getBoundingClientRect().height; })()";

0 commit comments

Comments
 (0)