Skip to content

feat(app): replay button with pause/play for streaming animation - #75

Open
shruti-tg wants to merge 2 commits into
excalidraw:mainfrom
shruti-tg:feat/add-replay-functionality
Open

shruti-tg wants to merge 2 commits into
excalidraw:mainfrom
shruti-tg:feat/add-replay-functionality

Conversation

@shruti-tg

@shruti-tg shruti-tg commented May 22, 2026 •

Copy link
Copy Markdown

Summary

Adds a Replay button to the inline toolbar that re-triggers the streaming SVG animation after the model has finished rendering. The button cycles through three states:

  • Replay (idle) → starts the stream
  • Pause (streaming) → cancels the next tick; rendered elements stay on screen
  • Play (paused) → resumes from the saved index

Reverts to Replay when the animation completes.

Motivation

The streaming draw-on animation is one of the most engaging parts of the widget, especially for educational diagrams (algorithm traces, step-by-step explanations). Today it only plays once — when the model first renders. Letting the user replay it makes the diagram a re-watchable artifact instead of a one-shot reveal.

Implementation

  • Replay pipeline: drives the same setToolInput / setInputIsFinal flow the MCP host uses, walking through the saved element array with setTimeout and feeding progressively larger slices as partials, then a final pass with the original JSON.
  • Reset: a replayKey counter is passed to DiagramView; bumping it clears latestRef, the SVG wrapper's innerHTML, and the count — so new nodes get the CSS fade-in/stroke draw-on animations instead of being preserved by morphdom.
  • Pause/resume state: lives in a replayStateRef (elements, index, timer) so pause can clearTimeout the pending tick and resume can re-schedule it without stale closures or re-renders per tick.
  • Toolbar visibility: the inline toolbar is hover-gated by default. Added a .main.replaying modifier so it stays pinned at opacity: 1 during the animation — otherwise the Pause button would disappear when the user moves the mouse off to watch.
  • Guards: button is hidden when userEdits exist (don't clobber edits persisted from a fullscreen session) and when no final input has been received yet.

Test plan

  • npm run dev:ui — load the Binary Search sample, wait for initial render, click Replay, then Pause mid-stream, then Play to resume
  • npm run serve + connect from Claude — render a diagram, click Replay, verify the animation replays from scratch with hand-drawn fade-in
  • Click Replay twice rapidly — second click is a no-op (guarded by isReplaying)
@vercel

vercel Bot commented May 22, 2026

Copy link
Copy Markdown

@shruti-tg is attempting to deploy a commit to the Excalidraw Team on Vercel.

A member of the Team first needs to authorize it.

@shruti-tg

shruti-tg commented May 22, 2026 •

Copy link
Copy Markdown
Author

PR up: #76

Screen.Recording.2026-05-22.at.6.24.41.PM.mov

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant