fix(studio): finish preparing the Journey PDF export

A sandboxed print frame cannot run the callback that bounds the wait for print assets. Run the timer in the app so an already settled SVG image cannot keep the Save as PDF button disabled.

Closes #3309
This commit is contained in:
Maurice
2026-12-03 11:01:25 +01:00
parent 75020dd2df
commit 8ae919c650
2 changed files with 48 additions and 5 deletions
+9 -5
View File
@@ -98,18 +98,22 @@ function settle(el: Element): Promise<void> {
* worse than a marker that prints blank.
*/
export async function whenReady(iframe: HTMLIFrameElement): Promise<void> {
const win = iframe.contentWindow;
const doc = iframe.contentDocument as PrintDocument | null;
if (!win || !doc) return;
if (!doc) return;
const imgs = Array.from(doc.images);
const svg = svgImagesToWait(doc);
const images = imgs.map((img) => (img.complete ? Promise.resolve() : settle(img)));
const wait = win.setTimeout?.bind(win) ?? setTimeout;
// The sandbox blocks the frame's timer callbacks. Keep the deadline in the app.
let timeout: ReturnType<typeof setTimeout> | undefined;
const ceiling = new Promise<void>((resolve) => {
wait(resolve, printReadyCeilingMs(imgs.length + svg.length));
timeout = setTimeout(resolve, printReadyCeilingMs(imgs.length + svg.length));
});
await Promise.race([Promise.all([...images, ...svg.map(settle), doc.fonts?.ready ?? Promise.resolve()]), ceiling]);
try {
await Promise.race([Promise.all([...images, ...svg.map(settle), doc.fonts?.ready ?? Promise.resolve()]), ceiling]);
} finally {
clearTimeout(timeout);
}
}