Skip to content

armgit / raea

Public Imported from GitHub
0

Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.

LR9: "raea" exports delayRender(label?, { timeoutInMilliseconds }), continueRender(handle) and cancelRender(error) on the frame hold <R3F> already uses: the frame isn't marked done while a hold is open, and the last release draws it, so a composition that measures after a font, a fetch or a timer has that frame taken, not the one before. A hold not continued within its timeout (30 s) fails the render naming its label; cancelRender fails it at once, as a throw does. Settle lets a held frame wait up to HOLD_SECS (120 s) instead of failing it at its 20 s stall guard, so the hold's own named failure comes first. probes/hold.tsx sets its words after a timer under a hold and matches Chrome; a never-continued hold fails in 2.6 s naming it. The manual has its page (reference/sdk/hold.md)

shinyobjectzb3fe2699d079
diff --git a/bench/layout-reads/probes/hold.tsx b/bench/layout-reads/probes/hold.tsx
new file mode 100644
index 00000000..fa91f9ac
--- /dev/null
+++ b/bench/layout-reads/probes/hold.tsx
@@ -0,0 +1,31 @@
+// LR9's hold as a probe (docs/layout-reads.feature): the composition holds its frame, sets its words after a timer
+// (as it would after a font or a fetch), and continues. The frame taken is the one with the words; a frame taken
+// before the hold was released would show "waiting" where Chrome, which dumps a second later, shows the words.
+import { AbsoluteFill, continueRender, delayRender } from "raea";
+import { loadFont } from "raea/text";
+import { useEffect, useRef, useState } from "react";
+
+const { fontFamily } = loadFont("Inter");
+
+export const conf = { width: 640, height: 200, fps: 30, durationInFrames: 3 };
+export const props = {};
+
+export function Comp() {
+ const [handle] = useState(() => delayRender("words after a timer"));
+ const [words, setWords] = useState("waiting");
+ const ref = useRef<HTMLDivElement>(null);
+ useEffect(() => {
+ const t = setTimeout(() => {
+ setWords("held until the words came");
+ continueRender(handle);
+ }, 300);
+ return () => clearTimeout(t);
+ }, [handle]);
+ return (
+ <AbsoluteFill style={{ background: "#fff", color: "#111", fontFamily, fontSize: 32 }}>
+ <div ref={ref} style={{ position: "absolute", left: 32, top: 70 }}>
+ {words}
+ </div>
+ </AbsoluteFill>
+ );
+}
diff --git a/docs/layout-reads.feature b/docs/layout-reads.feature
index e6383753..9f04d106 100644
--- a/docs/layout-reads.feature
+++ b/docs/layout-reads.feature
@@ -215,6 +215,7 @@ Feature: Layout reads: a composition measures its text and layout as Chrome does
Rule: the frame waits for the measure
+ @done
Scenario: LR9. delayRender and continueRender
Then "raea" exports delayRender(label?), continueRender(handle) and cancelRender(error) on the hold that @raea/r3f
already uses (__raeaHold)
@@ -222,6 +223,19 @@ Feature: Layout reads: a composition measures its text and layout as Chrome does
And a handle still open after the hold's timeout fails the render, naming its label
And a component written for this pattern (measure in an effect, then continue) draws its measured layout on the
held frame itself, not the frame after
+ And 11-12, built:
+ - sdk/raea/src/hold.ts. delayRender(label?, { timeoutInMilliseconds }) opens a hold. Its timer (30 s,
+ HOLD_TIMEOUT_MS) fails the render as `cancelRender: "LABEL" was held for N ms and never continued`.
+ continueRender releases it, and the last release wakes the frame. A handle released twice does nothing.
+ cancelRender sends a data-raea-error, which the render reports as a composition's throw.
+ - Settle's guard against a stalled frame (20 s with nothing moving) would have failed a held frame before
+ the hold's own timeout. A frame whose marker is at the frame but not done now waits up to HOLD_SECS
+ (120 s), then fails saying it was held. The same applies to <R3F> scenes that never finish loading,
+ which used to fail at 20 s.
+ - bench/layout-reads/probes/hold.tsx holds its frame, sets its words after a 300 ms timer, and continues.
+ The frames match Chrome's words. A composition whose hold is never continued fails in 2.6 s with its
+ label (timeout 2000 ms).
+ - The manual has a page for it, docs/manual/reference/sdk/hold.md.
Rule: it's finished when the harness passes, nothing got slower, and users can read about it
diff --git a/docs/manual/reference/sdk/hold.md b/docs/manual/reference/sdk/hold.md
new file mode 100644
index 00000000..7d02de2e
--- /dev/null
+++ b/docs/manual/reference/sdk/hold.md
@@ -0,0 +1,66 @@
+---
+title: "raea/hold"
+summary: "Holding a frame until it's ready: delayRender, continueRender and cancelRender."
+order: 27
+sources: ["sdk/raea/src/hold.ts"]
+---
+
+A frame is taken once the composition has rendered it. When the composition needs one more step first (a measure in an
+effect, a font, a fetch, a timer), it holds the frame with `delayRender` and releases it with `continueRender`; the
+frame is taken after the last hold is released, with what the composition did by then. A hold still open after its
+timeout (30 s unless `timeoutInMilliseconds` says otherwise) fails the render with its label, and `cancelRender` fails
+it at once, as a throw does.
+
+```tsx
+import { continueRender, delayRender } from "raea";
+
+const [handle] = useState(() => delayRender("measure the title"));
+useEffect(() => {
+ setWidth(title.current!.getBoundingClientRect().width);
+ continueRender(handle);
+}, []);
+```
+
+<R3F> opens the same hold while its scene loads, so the two wait for each other.
+
+<!-- generated:begin by tools/manual-ref/sdk.ts from the SDK's exports and doc comments; edit outside this block -->
+
+```ts
+import { cancelRender, continueRender, delayRender, HOLD_TIMEOUT_MS } from "raea/hold"
+```
+
+`raea/hold` exports 3 functions, 1 value. Source: [sdk/raea/src/hold.ts](https://github.com/shinyobjectz/raea/blob/main/sdk/raea/src/hold.ts).
+
+## Functions
+
+### `cancelRender`
+
+Fail the render: the error goes where a composition's throw goes (a data-raea-error the render reports and stops on).
+
+```ts
+function cancelRender(err: unknown): void
+```
+
+### `continueRender`
+
+Release a hold delayRender opened; the last one released wakes the frame. A handle already released does nothing.
+
+```ts
+function continueRender(handle: number): void
+```
+
+### `delayRender`
+
+Hold the frame until `continueRender(handle)`. `label` names it if it's still open when its time runs out.
+
+```ts
+function delayRender(label?: string, options?: { timeoutInMilliseconds?: number; } | undefined): number
+```
+
+## Values
+
+### `HOLD_TIMEOUT_MS`
+
+How long a hold may stay open before the render fails naming it, unless delayRender is told otherwise.
+
+<!-- generated:end -->
diff --git a/docs/manual/reference/sdk/index.md b/docs/manual/reference/sdk/index.md
index 98f3dbb2..200d3dc6 100644
--- a/docs/manual/reference/sdk/index.md
+++ b/docs/manual/reference/sdk/index.md
@@ -31,14 +31,14 @@ The composition, the app, and the specs and notes an agent writes.
| Import | What it's for | Exports |
| --- | --- | --- |
-| [`raea`](raea.md) | The main entry: compositions, sequences, time, interpolation, springs, footage, sound and words. | 18 components, 8 hooks, 52 functions, 8 values, 91 types |
+| [`raea`](raea.md) | The main entry: compositions, sequences, time, interpolation, springs, footage, sound and words. | 18 components, 8 hooks, 55 functions, 9 values, 91 types |
| [`raea/app`](app.md) | The App, its plugins and schedules, and the registry a video's compositions are kept in. | 1 component, 4 functions, 3 classes, 17 values, 8 types |
| [`raea/brief`](brief.md) | The specs an agent writes as data: brief, script, taste, plan and controller, checked against raea's schemas. | 5 functions, 28 types |
| [`raea/note`](note.md) | A person's note as a file in the project: their words kept as written, and the asks the agent restates it as. | 1 function, 4 types |
## Time and motion
-Frames, animation, springs, states and input.
+Frames, animation, springs, states and input, and holding a frame until it's ready.
| Import | What it's for | Exports |
| --- | --- | --- |
@@ -47,6 +47,7 @@ Frames, animation, springs, states and input.
| [`raea/math`](math.md) | Numbers through time: interpolation, easing, springs, curves and the vector types Bevy uses. | 7 functions, 3 values, 7 types |
| [`raea/state`](state.md) | State machines stepped by frame, for game logic and workflows, typed so a wrong transition doesn't compile. | 2 hooks, 6 functions, 1 value, 20 types |
| [`raea/input`](input.md) | The frame's input: keys, pointer, wheel and gamepads, the same live and in a scripted render. | 1 hook, 2 functions, 2 types |
+| [`raea/hold`](hold.md) | Holding a frame until it's ready: delayRender, continueRender and cancelRender. | 3 functions, 1 value |
## Video, sound and text
diff --git a/docs/manual/reference/sdk/raea.md b/docs/manual/reference/sdk/raea.md
index d9d70df6..8b491e67 100644
--- a/docs/manual/reference/sdk/raea.md
+++ b/docs/manual/reference/sdk/raea.md
@@ -38,7 +38,7 @@ See [Your first video](../../start/first-video.md) for the whole loop, and
import { AbsoluteFill, ACTION_KEY, actionsIn, Animate } from "raea"
```
-`raea` exports 18 components, 8 hooks, 52 functions, 8 values, 91 types. Source: [sdk/raea/src/index.tsx](https://github.com/shinyobjectz/raea/blob/main/sdk/raea/src/index.tsx).
+`raea` exports 18 components, 8 hooks, 55 functions, 9 values, 91 types. Source: [sdk/raea/src/index.tsx](https://github.com/shinyobjectz/raea/blob/main/sdk/raea/src/index.tsx).
## Components
@@ -353,6 +353,22 @@ function actionsIn(input: FrameInput): { name: string; args: any; }[]
function applyActions<S>(actions: PanelActions<S>, state: S, input: FrameInput): S
```
+### `cancelRender`
+
+Fail the render: the error goes where a composition's throw goes (a data-raea-error the render reports and stops on).
+
+```ts
+function cancelRender(err: unknown): void
+```
+
+### `continueRender`
+
+Release a hold delayRender opened; the last one released wakes the frame. A handle already released does nothing.
+
+```ts
+function continueRender(handle: number): void
+```
+
### `curveFn`
A curve name as a function (the engine's easing::Easing::parse, the same names).
@@ -369,6 +385,14 @@ The same move later by `frames`.
function delay(m: MoveLike, frames: number): Move
```
+### `delayRender`
+
+Hold the frame until `continueRender(handle)`. `label` names it if it's still open when its time runs out.
+
+```ts
+function delayRender(label?: string, options?: { timeoutInMilliseconds?: number; } | undefined): number
+```
+
### `fade`
opacity 0 to 1 over `frames` (6).
@@ -810,6 +834,10 @@ publishing { send: { n, text } } (a higher n is a new message); a panel drives t
The default decider: the first candidate.
+### `HOLD_TIMEOUT_MS`
+
+How long a hold may stay open before the render fails naming it, unless delayRender is told otherwise.
+
### `MEDIA_ROOT`
Where the space's media folder is served from.
diff --git a/runtime/react/src/scene/settle.rs b/runtime/react/src/scene/settle.rs
index 2e88646a..0636d667 100644
--- a/runtime/react/src/scene/settle.rs
+++ b/runtime/react/src/scene/settle.rs
@@ -31,6 +31,9 @@ pub const SETTINGS_SECS: f64 = 120.0;
/// One JS call running longer than this is a hang (a loop that never returns), not progress.
pub const HANG_SECS: f64 = 600.0;
+/// The longest a frame may be held (delayRender, a suspended scene) with nothing else moving.
+pub const HOLD_SECS: f64 = 120.0;
+
/// Run React until its commits settle and the marker says `want` (or anything, for None). A layout read the composition
/// makes meanwhile is told this host lays no page out: a host with a page settles with [`settle_with`].
pub fn settle(app: &mut App, want: Option<i64>, secs: f64) -> R<Option<Map<String, Value>>> {
@@ -52,6 +55,8 @@ pub fn settle_with(app: &mut App, want: Option<i64>, secs: f64, answer: &mut cra
let mut moved = (u64::MAX, u64::MAX, f64::NAN);
// the marker as last seen (frame, done), for the refusal's message
let mut marked = (-2i64, -2i64);
+ // the frame is held (below): its marker at the frame, not done
+ let mut held = false;
// the count before the first update: a flush is in the channel before it's counted, so one that landed before this
// read is applied by the update below, and one after it wakes the wait. (A first pass that waited for a flush
// before updating lost the frame's flush whenever React was quicker than this read: the wait then ran its 0.5 s
@@ -135,7 +140,10 @@ pub fn settle_with(app: &mut App, want: Option<i64>, secs: f64, answer: &mut cra
moved = now;
still = std::time::Instant::now();
}
- let left = secs - still.elapsed().as_secs_f64();
+ // a held frame (delayRender, a scene still loading: its marker at the frame, not done) waits up to
+ // HOLD_SECS, so a hold's own timeout (30 s unless it says) fails the render naming it first (layout-reads LR9)
+ held = want.is_some_and(|w| marked.0 == w && marked.1 != w);
+ let left = if held { secs.max(HOLD_SECS) } else { secs } - still.elapsed().as_secs_f64();
if left <= 0.0 {
break;
}
@@ -149,6 +157,9 @@ pub fn settle_with(app: &mut App, want: Option<i64>, secs: f64, answer: &mut cra
if let Some(d) = crate::js_call_for().filter(|d| d.as_secs_f64() >= HANG_SECS) {
return Err(format!("the composition hangs on frame {want:?}: {} has run for {:.0} s without returning (past {HANG_SECS} s: an endless loop, or a native call that never returns; `sample <pid>` shows where), its marker at frame {} (done {})", crate::js_call_who(), d.as_secs_f64(), marked.0, marked.1));
}
+ if held {
+ return Err(format!("frame {want:?} was held for {HOLD_SECS} s and never released: a delayRender never continued, or a scene that never finished loading"));
+ }
Err(format!("the composition made no progress on frame {want:?} for {secs} s, its marker at frame {} (done {}) (does it throw? its [js] lines are above, and `raea traces show last` has the run's log)", marked.0, marked.1))
}
diff --git a/sdk/guides/craft/motion.md b/sdk/guides/craft/motion.md
index 8bbfa9a8..2157c907 100644
--- a/sdk/guides/craft/motion.md
+++ b/sdk/guides/craft/motion.md
@@ -39,6 +39,9 @@ Read the files a task needs with `raea guide motion/NAME`, one or two at a time,
`useState`, `useEffect` and timers don't animate a render. `Math.random()` is seeded for each frame: a render
repeats, but every frame draws new numbers, so it suits grain or a flicker, and something that should hold still
(a scatter, a layout) is seeded from an index. `Date` (`Date.now()`, `new Date()`) is the frame's time.
+ A frame that needs one more step before it's taken (text measured in an effect, a fetch) holds it with
+ `delayRender("what it waits for")` and releases it with `continueRender(handle)` (`raea/hold`); a hold never
+ released fails the render after 30 s, naming its label.
3. **Clamp every interpolate.** The default extrapolation extends the line forever, so use
`{extrapolateLeft: "clamp", extrapolateRight: "clamp"}` unless you mean otherwise. Inputs must strictly increase.
4. **Settle with `Easing.out(Easing.cubic)`.** The plain curves (`Easing.cubic`, `Easing.quad`) ease in, and
diff --git a/sdk/raea/src/hold.ts b/sdk/raea/src/hold.ts
new file mode 100644
index 00000000..d50266b4
--- /dev/null
+++ b/sdk/raea/src/hold.ts
@@ -0,0 +1,44 @@
+// A frame held until the composition says it's ready (docs/layout-reads.feature LR9): delayRender opens a hold on raea's
+// frame, continueRender closes it, cancelRender fails the render. It's the hold <R3F> already opens while a scene loads
+// (globalThis.__raeaHold, the entry's HOLD): while any is open the frame isn't marked done, and closing the last wakes
+// it, so the frame is taken with what the composition did before it continued (a measure in an effect, a font, a
+// fetch), not before.
+
+type Hold = { n: number; wake: Set<() => void>; open?: Map<number, string> };
+
+const HOLD = ((globalThis as { __raeaHold?: Hold }).__raeaHold ??= { n: 0, wake: new Set() });
+const OPEN = (HOLD.open ??= new Map());
+let next = 1;
+let failures = 0;
+
+/** How long a hold may stay open before the render fails naming it, unless delayRender is told otherwise. */
+export const HOLD_TIMEOUT_MS = 30000;
+
+/** Fail the render: the error goes where a composition's throw goes (a data-raea-error the render reports and stops on). */
+export function cancelRender(err: unknown): void {
+ const msg = err instanceof Error ? err.message : String(err);
+ const host = (globalThis as { __bevyHost?: { op_flush?: (json: string, devtools: boolean) => void } }).__bevyHost;
+ if (!host?.op_flush) throw err instanceof Error ? err : new Error(msg);
+ // an element of its own carrying the error, never put on the page: the render reads it as the batch lands
+ host.op_flush(JSON.stringify([{ op: "create", id: 2 ** 52 + failures++, kind: "div", props: { "data-raea-error": `cancelRender: ${msg}` } }]), false);
+}
+
+/** Hold the frame until `continueRender(handle)`. `label` names it if it's still open when its time runs out. */
+export function delayRender(label?: string, options?: { timeoutInMilliseconds?: number }): number {
+ const handle = next++;
+ const name = label ?? `delayRender() #${handle}`;
+ OPEN.set(handle, name);
+ HOLD.n++;
+ const ms = options?.timeoutInMilliseconds ?? HOLD_TIMEOUT_MS;
+ setTimeout(() => {
+ if (OPEN.has(handle)) cancelRender(new Error(`"${name}" was held for ${ms} ms and never continued (continueRender(${handle}))`));
+ }, ms);
+ return handle;
+}
+
+/** Release a hold delayRender opened; the last one released wakes the frame. A handle already released does nothing. */
+export function continueRender(handle: number): void {
+ if (!OPEN.delete(handle)) return;
+ HOLD.n = Math.max(0, HOLD.n - 1);
+ if (HOLD.n === 0) for (const w of [...HOLD.wake]) w();
+}
diff --git a/sdk/raea/src/index.tsx b/sdk/raea/src/index.tsx
index 84389b28..db72cb39 100644
--- a/sdk/raea/src/index.tsx
+++ b/sdk/raea/src/index.tsx
@@ -70,6 +70,8 @@ export {
export { Overlay, overlays } from "@raea/video/overlay";
export type { FrameInput, InputTimeline, Perception, Rect } from "@raea/app/clock";
export { Mix, type MixProps } from "@raea/audio/mix";
+// a frame held until the composition continues it (docs/layout-reads.feature LR9)
+export { delayRender, continueRender, cancelRender, HOLD_TIMEOUT_MS } from "./hold";
export {
Animate, Stagger, propsFingerprint, track, move, delay, reverse, curve, curveFn, timeline, sequence, sequenceGap, parallel, stagger, gridDelay, sampleAnimation,
rise, pop, slam, slide, wipe, fill, tick, strike, pushIn, fade, moves, toMove,
diff --git a/skills b/skills
index ae8002cf..f7e89d0c 160000
--- a/skills
+++ b/skills
@@ -1 +1 @@
-Subproject commit ae8002cfa13d8936411b7b73b4d1e8ce2b6bed52
+Subproject commit f7e89d0c45a2a932c0fd7dcc1db0f1f0c60fd82d
diff --git a/tools/manual-ref/sdk.ts b/tools/manual-ref/sdk.ts
index 1319aaed..a203af5c 100644
--- a/tools/manual-ref/sdk.ts
+++ b/tools/manual-ref/sdk.ts
@@ -23,7 +23,7 @@ const problems: string[] = []
// the index's groups, in the order a reader meets them; every import path is in one
const GROUPS: [string, string, string[]][] = [
["Start here", "The composition, the app, and the specs and notes an agent writes.", ["raea", "app", "brief", "note"]],
- ["Time and motion", "Frames, animation, springs, states and input.", ["time", "animation", "math", "state", "input"]],
+ ["Time and motion", "Frames, animation, springs, states and input, and holding a frame until it's ready.", ["time", "animation", "math", "state", "input", "hold"]],
["Video, sound and text", "Footage, pictures, sound, words and colour.", ["video", "audio", "text", "image", "asset", "color"]],
["3D", "Bevy's 3D: cameras, lights, materials, meshes and the frame after it's drawn.", ["3d", "camera", "light", "pbr", "mesh", "transform", "post_process", "picking", "gizmos"]],
["2D and UI", "Sprites and flat shapes, bevy_ui and Bevy's widgets.", ["sprite", "ui", "feathers"]],