Skip to content

The VS Code of video editing, built for agents.

TypeScript

Improve canvas handling and error logging in rendering

konstantin-paulus0197f512995b
diff --git a/apps/web/src/engine/capture.ts b/apps/web/src/engine/capture.ts
index fa6bc2d3..f326baaa 100644
--- a/apps/web/src/engine/capture.ts
+++ b/apps/web/src/engine/capture.ts
@@ -93,11 +93,18 @@ export async function createCapture(source: World, node: Entity, options: Captur
// Created before the world is filled: the DOM-backed paints (`<html>`,
// `<htmlPaint>`) attach their layout roots to it as their element is made.
- // The encoder sizes it once it knows how big the picture is.
+ // The encoder sizes it once it knows how big the picture is. It sits inside
+ // the viewport, behind the app, not parked off-screen: the browser only
+ // paints layout near the viewport, and drawElementImage draws from that
+ // cached paint — on a canvas at left:-100000px it throws "no cached paint
+ // record" and every HTML paint captures blank. The opacity keeps it from
+ // showing through translucent UI above it (the rendering overlay) while
+ // staying over Chromium's minimum visible opacity (0.0004), under which the
+ // subtree would again not be painted.
const canvas = document.createElement('canvas');
canvas.width = 2;
canvas.height = 2;
- canvas.style.cssText = 'position:fixed;left:-100000px;top:0;pointer-events:none;';
+ canvas.style.cssText = 'position:fixed;left:0;top:0;z-index:-9999;opacity:0.001;pointer-events:none;';
document.body.appendChild(canvas);
// Shares the source's assets and generation service — a `src` names the
diff --git a/examples/05-anime-timeline.tsx b/examples/05-anime-timeline.tsx
index d7aa0cd5..713b75a9 100644
--- a/examples/05-anime-timeline.tsx
+++ b/examples/05-anime-timeline.tsx
@@ -68,7 +68,10 @@ export default function AnimeTimeline() {
<div style={{ "font-size": "34px", "font-weight": "700", color: `hsl(${hue()} 90% 65%)` }}>
DOM, meet timeline
</div>
- <div style={{ "font-size": "18px", opacity: 0.7, margin: "6px 0 24px" }}>
+ {/* Dimmed via alpha colors, not opacity: a fractional opacity here
+ would nest under the wrapper's animated one, which blanks the
+ subtree mid-fade (see reference/jsx/html.md limitations). */}
+ <div style={{ "font-size": "18px", color: "rgba(255,255,255,0.7)", margin: "6px 0 24px" }}>
anime.js seeked from the playhead at t = {time().toFixed(2)}s
</div>
<div style={{ height: "14px", "border-radius": "7px", background: "#ffffff22" }}>
@@ -81,7 +84,7 @@ export default function AnimeTimeline() {
}}
/>
</div>
- <div style={{ "font-size": "16px", opacity: 0.6, "margin-top": "10px" }}>
+ <div style={{ "font-size": "16px", color: "rgba(255,255,255,0.6)", "margin-top": "10px" }}>
{Math.round(v.card.progress)}% through the loop
</div>
</div>
diff --git a/packages/runtime/src/systems/render.ts b/packages/runtime/src/systems/render.ts
index 948ebdab..0687ebe3 100644
--- a/packages/runtime/src/systems/render.ts
+++ b/packages/runtime/src/systems/render.ts
@@ -257,6 +257,10 @@ type DrawElementContext = Ctx2D & {
};
+// Roots whose last drawElementImage threw, so a persistent failure logs once
+// rather than flooding the console; drawing again clears the entry.
+const failedHtmlRoots = new WeakSet<HTMLElement>();
+
function renderHtmlFill(world: World, entity: Entity, source: Entity): void {
const root = source.get(Host)?.element;
const surface = world.get(RenderSurface);
@@ -278,7 +282,10 @@ function renderHtmlFill(world: World, entity: Entity, source: Entity): void {
try {
(ctx as DrawElementContext).drawElementImage(root, 0, 0, width, height);
} catch (error) {
- console.error(`Error drawing <HtmlPaint> content: ${error instanceof Error ? `${error.name}: ${error.message}` : error}`);
+ if (!failedHtmlRoots.has(root)) {
+ failedHtmlRoots.add(root);
+ console.error(`Error drawing <HtmlPaint> content: ${error instanceof Error ? `${error.name}: ${error.message}` : error}`);
+ }
}
ctx.restore();
diff --git a/reference/jsx/html.md b/reference/jsx/html.md
index cf2ad017..c73bad2d 100644
--- a/reference/jsx/html.md
+++ b/reference/jsx/html.md
@@ -83,4 +83,4 @@ The module is re-executed in every context: on reload, export, and [`dapi captur
- Pointer and media event handlers on the DOM children are ignored: the subtree is rasterized into the canvas, not interacted with. Styles, classes, attributes, `innerHTML` and `textContent` all apply and are reactive.
- **`<html>` is sourceless, so with no `end` it defaults to a 16-second duration and disappears after 16 s** — a silent cutoff with no error.
- **`scale()` blanks large or clipped subtrees in captures.** The rasterizer renders a subtree as *empty* when a CSS `scale()` sits on a large wrapper (e.g. a full-box `width:100%;height:100%` group), or when any `overflow:hidden` clip lives beneath a scaled ancestor. Animate entrances, holds, and exits with `translate` and `opacity`; use `scale` only on small, content-sized leaf elements with no clipping inside them. A masked text reveal (`overflow:hidden` + inner `translateY`) is fine as long as no ancestor of the mask carries a transform.
-- **Nested fractional `opacity` blanks the subtree in captures.** A child with `opacity` < 1 under an ancestor whose `opacity` is also < 1 makes the rasterizer drop the ancestor's entire subtree for exactly as long as the ancestor's opacity is fractional — so a wrapper fading in over children styled with `opacity: 0.7` is blank mid-fade and pops in the moment the fade lands on 1. Keep animated `opacity` to a single level of the tree: dim static children with alpha colors (`rgba()` / `hsl()` alpha) instead of `opacity`.
+- **Nested fractional `opacity` blanks the subtree in captures.** A child with `opacity` < 1 under an ancestor whose `opacity` is also < 1 makes the rasterizer drop the ancestor's entire subtree for exactly as long as the ancestor's opacity is fractional — so a wrapper fading in over children styled with `opacity: 0.7` is blank mid-fade and pops in the moment the fade lands on 1. In the live editor the dropped subtree does not just go blank: the promoted layer escapes the canvas and paints itself on top of the stage at the canvas's top-left corner, at authored size, with no camera or scene transform — HTML content appearing untransformed over the stage instead of inside its scene is this bug, not a broken transform. Keep animated `opacity` to a single level of the tree: dim static children with alpha colors (`rgba()` / `hsl()` alpha) instead of `opacity`.