Skip to content

docs(visuals): document renderer clear-highlights contract at end of playback#234

Merged
mellonis merged 1 commit into
masterfrom
docs/visuals-playback-clear-contract
Jun 9, 2026
Merged

docs(visuals): document renderer clear-highlights contract at end of playback#234
mellonis merged 1 commit into
masterfrom
docs/visuals-playback-clear-contract

Conversation

@mellonis

@mellonis mellonis commented Jun 9, 2026

Copy link
Copy Markdown
Owner

Doc-only follow-up to machines-demo#108 / machines-demo PR #109.

Why

The README's "Example: playing a snippet" walked through the auto-play loop but didn't say what the renderer must do once the player stops advancing. machines-demo hit this in production — the residual halt-iter highlight stayed painted on the graph forever after `forward()` returned `false`, reading as "playback froze before halt" rather than "the machine halted."

That's actually a renderer-loop concern, not a recording concern: `recordSnippet` faithfully captures one Frame per iter (the last one IS the halt iter with `highlight.toId === 0`); whether to clear the highlight when the animation loop stops is up to the consumer. machines-demo fixed it consumer-side in PR #109. This PR documents the contract upstream so future consumers know the same.

What

Adds a "Renderer contract: clearing highlights at end of playback" subsection between the `SnippetPlayer` pure-state paragraph and the Versioning section. The new prose:

  • Names `recordSnippet`'s faithful one-frame-per-iter shape: NO synthetic "settled" frame is appended; the last frame is the halt iter with `highlight.toId === 0`, `strong: 'from'`.
  • Tells consumers to clear highlight classes when `forward()` stops returning `true` (and in any equivalent settled-on-final-frame path — `back()` reaching 0, manual `goTo(idx)` to final, etc.).
  • Notes the recorder leaves the clear step to the renderer on purpose.
  • Calls out the reduced-motion variant: keeping or clearing the halt-iter highlight is a consumer choice.

Includes the diff-shaped code snippet showing the `clearHighlightClasses(ops)` call inside the `if (!player.forward()) { ... }` branch.

Rejected alternative — append a `highlight: null` settled frame to `recordSnippet`

Tempting because it would auto-fix any future consumer without them reading docs. But:

  • Frame shape lies a bit: `frames.length` becomes `iterCount + 2` instead of `iterCount + 1`, and the extra frame doesn't represent an iter.
  • Frame shape encodes consumer behavior — recorder picks "clear on the last tick" for everyone.
  • A flag on the halt iter (or just `highlight.toId === 0`) already lets consumers detect the halt iter if they need to render differently.

The "faithful recording + documented consumer contract" framing is cleaner.

No source change

`recordSnippet.ts`, `snippetPlayer.ts`, and the snippet `.spec.ts` files are unchanged. No version bump. CHANGELOG unchanged. Docs-only.

Verification

  • README renders cleanly (no broken Markdown).
  • 669/669 tests still pass (unchanged).

…playback

The README's "Example: playing a snippet" walked through the auto-play
loop but didn't say what the renderer must do once the player stops
advancing. machines-demo hit this as #108 — the residual halt-iter
highlight stayed painted on the graph forever after `forward()`
returned false, reading as "playback froze before halt" rather than
"the machine halted."

Adds a "Renderer contract" subsection that:

- Names recordSnippet's faithful one-frame-per-iter shape (NO synthetic
  "settled" frame is appended; the last frame is the halt iter with
  highlight.toId === 0, strong: 'from').
- Tells consumers to clear highlight classes when `forward()` stops
  returning true (and in any equivalent settled-on-final-frame path).
- Notes that the recorder leaves the clear-step to the renderer on
  purpose — animation-loop concern, not a recording concern.
- Calls out reduced-motion: keeping or clearing the halt-iter highlight
  is a consumer choice (recorder doesn't dictate).

No source change — recordSnippet behavior is unchanged. Docs-only.
@mellonis mellonis merged commit 74be463 into master Jun 9, 2026
3 checks passed
@mellonis mellonis deleted the docs/visuals-playback-clear-contract branch June 9, 2026 10:30
@github-project-automation github-project-automation Bot moved this from Todo to Done in @mellonis's machines Jun 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant