Skip to content

Write HTML. Render video. Built for agents.

docs(examples): reset control state on offscreen release; precise a11y labels

ukimsanovf3d1d531d138
diff --git a/docs/reference/html-schema.mdx b/docs/reference/html-schema.mdx
index 05e88af7b0..3b77b80277 100644
--- a/docs/reference/html-schema.mdx
+++ b/docs/reference/html-schema.mdx
@@ -122,7 +122,7 @@ Audio has no visual lifecycle.
| Attribute | Applies to | Meaning |
| --- | --- | --- |
-| `data-media-start` / `data-playback-start` | Video, audio, nested composition | Offset into the source file, used by trim and split. Two groups of readers disagree, so the right name depends on the element. **Read only `data-media-start`:** the timing compiler, the HTML parser, `hyperframes validate`, and the engine's audio mixer (which feeds ffmpeg `-ss`). **Read `data-playback-start` first, falling back to `data-media-start`:** the runtime player, Studio (which also writes it), and `hyperframes snapshot`. Because the audio mixer reads only `data-media-start`, a `<video>` authored with just `data-playback-start` renders a trimmed picture over untrimmed audio. So set the name by kind: **`<video>` / `<audio>` → `data-media-start`**; **nested composition → `data-playback-start`** (Studio writes it, and it is the [child-timeline offset](/concepts/compositions)). |
+| `data-media-start` / `data-playback-start` | Video, audio, nested composition | Offset into the source file, used by trim and split. Two groups of readers disagree, so the right name depends on the element. **Read only `data-media-start`:** the timing compiler, the HTML parser, `hyperframes validate` (which only inspects `<audio>`), and the engine's audio mixer (which feeds ffmpeg `-ss`). **Read `data-playback-start` first, falling back to `data-media-start`:** the runtime player, Studio (which also writes it), and `hyperframes snapshot`. Because the audio mixer reads only `data-media-start`, a `<video>` authored with just `data-playback-start` renders a trimmed picture over untrimmed audio. Set the name by kind: **`<video>` / `<audio>` → `data-media-start`**; **nested composition → `data-playback-start`** — none of the media-start-only readers inspect a composition host, so its offset is only ever read as `data-playback-start` (Studio writes it; it is the [child-timeline offset](/concepts/compositions)). |
| `data-playback-rate` | Video, audio, nested composition | Playback multiplier from `0.1` to `5` |
| `data-volume` | Video and audio | Static volume from `0` to `1` |
| `data-has-audio="true"` | Video | Declares that the video contributes audio |
diff --git a/docs/snippets/hover-video.jsx b/docs/snippets/hover-video.jsx
index aa31859c68..ea41b6d955 100644
--- a/docs/snippets/hover-video.jsx
+++ b/docs/snippets/hover-video.jsx
@@ -110,7 +110,9 @@ export const HoverVideo = ({ src, poster, className, hasAudio = true }) => {
aria-label={
hasAudio
? muted
- ? "Play this preview with sound"
+ ? reduced
+ ? "Play this preview with sound"
+ : "Unmute this preview"
: "Mute this preview"
: playing
? "Pause this preview"
diff --git a/docs/snippets/replica-compare.jsx b/docs/snippets/replica-compare.jsx
index 60fe6fb998..ccfe4efaa4 100644
--- a/docs/snippets/replica-compare.jsx
+++ b/docs/snippets/replica-compare.jsx
@@ -55,9 +55,13 @@ export const ReplicaCompare = ({
for (const video of videos) {
if (!video) continue;
video.pause();
+ video.muted = true;
video.removeAttribute("src");
video.load();
}
+ // Reset the control's state too, so a card unmuted before it scrolled away
+ // doesn't return reading "Sound on" over a paused, sourceless pair.
+ setMuted(true);
return;
}
if (reduced) {
@@ -151,7 +155,15 @@ export const ReplicaCompare = ({
type="button"
onClick={toggleSound}
aria-pressed={!muted}
- aria-label={muted ? "Play the reference with sound" : "Mute the reference"}
+ aria-label={
+ muted
+ ? reduced
+ ? "Play the comparison with sound"
+ : "Unmute the reference"
+ : reduced
+ ? "Pause the comparison"
+ : "Mute the reference"
+ }
className="absolute left-3 top-3 z-10 flex items-center gap-1.5 rounded-full bg-black/60 px-3 py-1.5 text-xs font-medium text-white backdrop-blur transition hover:bg-black/75 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-white"
>
{muted ? (
diff --git a/scripts/check-docs-snippet-motion.test.mjs b/scripts/check-docs-snippet-motion.test.mjs
index 821c660042..b8903a5ba2 100644
--- a/scripts/check-docs-snippet-motion.test.mjs
+++ b/scripts/check-docs-snippet-motion.test.mjs
@@ -134,12 +134,25 @@ test("every autoplaying component in docs/snippets currently satisfies the guard
// reason).
test("ReplicaCompare's control starts both films and does not gate sync on reduced motion", () => {
const source = readFileSync(join(here, "../docs/snippets/replica-compare.jsx"), "utf8");
- // The voluntary-play path starts both the reference and the replica.
- assert.match(source, /refVideo\.current\?\.play\(\)/, "reference is started");
- assert.match(source, /repVideo\.current\?\.play\(\)/, "replica is started too");
+ // startBoth must play both elements...
+ const startBoth = source.match(/const startBoth = \(\) => \{([\s\S]*?)\n {2}\};/);
+ assert.ok(startBoth, "found startBoth");
+ assert.match(startBoth[1], /refVideo\.current\?\.play\(\)/, "reference is started");
+ assert.match(startBoth[1], /repVideo\.current\?\.play\(\)/, "replica is started too");
+ // ...and the voluntary-play control must actually route through it, not play
+ // the reference alone (scoped to toggleSound so a helper left defined but
+ // unused can't satisfy the check — the exact regression this guards).
+ const toggle = source.match(/const toggleSound = \(\) => \{([\s\S]*?)\n {2}\};/);
+ assert.ok(toggle, "found toggleSound");
+ assert.match(toggle[1], /startBoth\(\)/, "voluntary play goes through startBoth");
// The replica-sync effect attaches in view regardless of the preference, so a
// voluntary play under reduced motion still pulls the replica along.
const syncGate = source.match(/const b = repVideo\.current;\s*\n\s*if \(([^)]*)\) return;/);
assert.ok(syncGate, "found the replica-sync guard");
assert.doesNotMatch(syncGate[1], /reduced/, "sync must not early-return on reduced motion");
+ // Offscreen release must reset the control's state, or a card unmuted before it
+ // scrolled away returns reading "Sound on" over a paused, sourceless pair.
+ const teardown = source.match(/if \(!inView\) \{([\s\S]*?)return;\n {4}\}/);
+ assert.ok(teardown, "found the offscreen teardown");
+ assert.match(teardown[1], /setMuted\(true\)/, "offscreen release resets muted state");
});