You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Composition canvas 2D context is missing setTransform and createImageData #55
From #13's run of snapcn's free components through raea: in a composition, a <canvas>'s 2D context lacks part of the API.
ctx.setTransform(...) is not a function. This crashes dot-bloom at frame 15.
ctx.createImageData(w, h) is not a function. This crashes orb-swarm at frame 80.
@raea/ui's canvas context (sdk/ui/src/canvas/context.ts), the one an app page uses, has both, along with measureText and getImageData. A composition's canvas is a different, smaller one. Same root as #54: a composition's elements aren't the app DOM.
While reading the composition path on main (0ea4eab) for this and #56, I found something that may bear on the runtime decision.
A composition's <canvas> ref is bevy-react 0.8.1's canvas element. Its CanvasContext (bevy-react/src/canvas.ts) records commands and sends them as {op: "update", kind: "canvas", props: {drawAppend}} (bridge.ts:314). I can't find anything in raea that reads drawAppend. page-ops paints a canvas only from __canvas2d (systems/page-ops/src/lib.rs:243, systems/canvas/src/lib.rs:49), the prop that sdk/ui's context sends. If that's right, adding setTransform and createImageData to bevy-react's context would stop the two crashes, but dot-bloom and orb-swarm would still draw an empty canvas. I haven't confirmed this with a render yet.
If you'd rather not wait on the runtime decision, here is a small change that could be deleted later:
Composition canvas 2D context is missing setTransform and createImageData #55:sdk/ui/src/canvas/context.ts sends everything through one send() (:61-70, wire.set(id, "__canvas2d", …)). It would get an optional sink, and getContext("2d") on a composition's canvas would return that context with a sink that sends __canvas2d through bevy-react's channel. Compositions would then get the full context (transforms, text, measureText, image data) with no Rust change. getImageData would still read zeros there, because canvas.read is only registered for app pages. context.ts is at 479 of the 500 lines tools/size.sh allows, so the sink would be a few lines.
Compositions lack requestAnimationFrame and Image #56: a raea-owned sdk/raea/src/frame-globals.ts, installed only where a global is missing (as pure.ts pins Math.random and Date). It would add requestAnimationFrame, with callbacks run once per frame step from setF (runtime/bundle/src/entry.rs:92) at f * 1000 / fps so they stay deterministic, and a small Image that resolves /media/ paths the way <img> does. pulsing-border would still fail after this, since @paper-design/shaders-react needs WebGL2.
Would you take that as a PR, or wait for the runtime decision? Either is fine. I'm working with Claude Code on a source build.
Fixed on main in 645b085; it ships in 0.1.3. @Razepriv, your reading was right: bevy-react's canvas context records an API nothing in raea draws. I went the way you sketched, so no PR is needed. Thank you for working it out.
In a composition, ref.current.getContext("2d") is now @raea/ui's CanvasRenderingContext2D, the same context an app page has: setTransform, createImageData, paths, text, gradients and measureText (estimated in a composition). Its display list goes to the element as __canvas2d, which the page already drew for app pages. canvas.width and canvas.height read the element's props (300 x 150 when unset). Setting them resizes and clears the bitmap, as in a browser.
One limit: getImageData reads zeros in a composition, since there's nothing to read pixels back from.
Checked: red drawn, then lime under setTransform(1, 0, 0, 1, 50, 50), both land where Chrome puts them, across a 10-frame MP4.
Activity
Razepriv commentedon Nov 11, 2026
While reading the composition path on main (0ea4eab) for this and #56, I found something that may bear on the runtime decision.
A composition's
<canvas>ref is bevy-react 0.8.1's canvas element. ItsCanvasContext(bevy-react/src/canvas.ts) records commands and sends them as{op: "update", kind: "canvas", props: {drawAppend}}(bridge.ts:314). I can't find anything in raea that readsdrawAppend. page-ops paints a canvas only from__canvas2d(systems/page-ops/src/lib.rs:243,systems/canvas/src/lib.rs:49), the prop thatsdk/ui's context sends. If that's right, addingsetTransformandcreateImageDatato bevy-react's context would stop the two crashes, but dot-bloom and orb-swarm would still draw an empty canvas. I haven't confirmed this with a render yet.If you'd rather not wait on the runtime decision, here is a small change that could be deleted later:
sdk/ui/src/canvas/context.tssends everything through onesend()(:61-70,wire.set(id, "__canvas2d", …)). It would get an optional sink, andgetContext("2d")on a composition's canvas would return that context with a sink that sends__canvas2dthrough bevy-react's channel. Compositions would then get the full context (transforms, text,measureText, image data) with no Rust change.getImageDatawould still read zeros there, becausecanvas.readis only registered for app pages.context.tsis at 479 of the 500 linestools/size.shallows, so the sink would be a few lines.sdk/raea/src/frame-globals.ts, installed only where a global is missing (aspure.tspinsMath.randomandDate). It would addrequestAnimationFrame, with callbacks run once per frame step fromsetF(runtime/bundle/src/entry.rs:92) atf * 1000 / fpsso they stay deterministic, and a smallImagethat resolves/media/paths the way<img>does. pulsing-border would still fail after this, since@paper-design/shaders-reactneeds WebGL2.Would you take that as a PR, or wait for the runtime decision? Either is fine. I'm working with Claude Code on a source build.
Compositions get the web's canvas 2D context, requestAnimationFrame a…
shinyobjectz commentedon Nov 12, 2026
Fixed on main in 645b085; it ships in 0.1.3. @Razepriv, your reading was right: bevy-react's canvas context records an API nothing in raea draws. I went the way you sketched, so no PR is needed. Thank you for working it out.
In a composition,
ref.current.getContext("2d")is now @raea/ui'sCanvasRenderingContext2D, the same context an app page has:setTransform,createImageData, paths, text, gradients andmeasureText(estimated in a composition). Its display list goes to the element as__canvas2d, which the page already drew for app pages.canvas.widthandcanvas.heightread the element's props (300 x 150 when unset). Setting them resizes and clears the bitmap, as in a browser.One limit:
getImageDatareads zeros in a composition, since there's nothing to read pixels back from.Checked: red drawn, then lime under
setTransform(1, 0, 0, 1, 50, 50), both land where Chrome puts them, across a 10-frame MP4.Skills for 0.1.3: raea pins raea-skills main e58e2a2 (#55, Solari's t…