All Challenges

Undo / Redo State History Stack

TypeScriptMediumFigmaCanvaExcalidraw
30:00

Problem Brief

Implement an Undo/Redo command stack (`past`, `present`, `future`) for a live text/action canvas with disabled boundary states.

Requirements

  • Each action committed via `[data-testid="commit-btn"]` pushes current text to `past` and clears `future`.
  • `[data-testid="undo-btn"]` pops last state into `[data-testid="doc-input"]`; `[data-testid="redo-btn"]` restores it.
  • Disable Undo when `past.length === 0` and Redo when `future.length === 0`.
Progressive Hints (1)
  • Keep `{ past: string[], present: string, future: string[] }` and sync button `.disabled` flags cleanly.
Reference Solution

Stuck? Load the verified reference code into your editor.

Automated Test Suite

1 Test Cases Ready
  • Supports Undo, Redo, and future stack clearing on new commitCommit v2 -> Undo back to v1 -> Redo to v2 -> Undo -> Commit v3 disables Redo
solution.html
Live Sandboxed Previewiframe sandbox
Starter template loaded — add your <script> logic in the editor (or open Reference Solution) to make the widget interactive.