Skip to content

The VS Code of video editing, built for agents.

TypeScript

Refactor HtmlHost readiness mechanism for improved resource handling

konstantin-paulusad3d540026c7
diff --git a/apps/web/src/components/engine/decoders/html.ts b/apps/web/src/components/engine/decoders/html.ts
index ba69eac7..bc7fea57 100644
--- a/apps/web/src/components/engine/decoders/html.ts
+++ b/apps/web/src/components/engine/decoders/html.ts
@@ -103,23 +103,18 @@ export class HtmlHost {
}
/**
- * Resolves once this host is safe to rasterize: every `<img>` in its
- * subtree has decoded (or failed), and only then does the rendering update
- * that refreshes the paint records run. Offline renders await this per
- * frame, so an image still in flight can't paint as an empty box, and a
- * source that lands late still makes it into the records that frame.
+ * Resolves asynchronously loaded html resources.
*/
public whenReady(): Promise<void> {
- const decoding: Promise<unknown>[] = [];
+ const pending: Promise<unknown>[] = [document.fonts.ready];
for (const image of this.element.querySelectorAll('img')) {
// `complete` covers loaded, failed, and srcless images alike; the
// rest are still in flight, and a failed decode just paints nothing.
if (image.complete) continue;
- decoding.push(image.decode().catch(() => undefined));
+ pending.push(image.decode().catch(() => undefined));
}
- if (decoding.length === 0) return nextRenderingUpdate();
- return Promise.all(decoding).then(() => nextRenderingUpdate());
+ return Promise.all(pending).then(() => nextRenderingUpdate());
}
public setSize(width: number, height: number): void {
diff --git a/reference/jsx/fonts.md b/reference/jsx/fonts.md
index 503691c7..dce05467 100644
--- a/reference/jsx/fonts.md
+++ b/reference/jsx/fonts.md
@@ -22,7 +22,7 @@ In [`<html>`](./html.md) you style text with ordinary CSS, so **use a locally in
</html>
```
-Remote web fonts (a Google Fonts `<link>`, or an `@font-face` with a `url()` source) do render, but nothing waits for the fetch. Stay on local families from [`dapi fonts`](../fonts.md) and the output is deterministic.
+Remote web fonts work too (a Google Fonts `<link>`, or an `@font-face` with a `url()` source). However the cost is that every render then depends on the network and on the font host staying up, so a local family from [`dapi fonts`](../fonts.md) is the safer default for anything you have to be able to re-render on demand.
If you want to pin an exact variant, declare an `@font-face` whose source is the CSS `local()` string that `dapi fonts` reports for that variant (never a `url()`):