Skip to content

perf(DesignerV2): Undo/Redo improvements + enabling#9027

Merged
rllyy97 merged 3 commits intomainfrom
riley/undo-redo-improvements
Apr 7, 2026
Merged

perf(DesignerV2): Undo/Redo improvements + enabling#9027
rllyy97 merged 3 commits intomainfrom
riley/undo-redo-improvements

Conversation

@rllyy97
Copy link
Copy Markdown
Contributor

@rllyy97 rllyy97 commented Apr 7, 2026

Commit Type

  • feature - New functionality
  • fix - Bug fix
  • refactor - Code restructuring without behavior change
  • perf - Performance improvement
  • docs - Documentation update
  • test - Test-related changes
  • chore - Maintenance/tooling

Risk Level

  • Low - Minor changes, limited scope
  • Medium - Moderate changes, some user impact
  • High - Major changes, significant user/system impact

What & Why

Undo/redo existed but was unusable: no triggers (keyboard or UI), and the default history size was 0 so state was never saved. This PR wires it up, fixes the defaults, and optimizes snapshot compression.

Enabling & Triggers

  • Keyboard shortcuts: Ctrl+Z / Ctrl+Y (+ Ctrl+Shift+Z) via react-hotkeys-hook in Designer.tsx. Disabled in read-only/monitoring mode.
  • VS Code command bar: Undo/Redo buttons added to the overflow menu in DesignerCommandBar/indexV2.tsx. Disabled when there is nothing to undo/redo or when not in designer view.
  • DEFAULT_MAX_STATE_HISTORY_SIZE: Changed from 020 so history is actually saved by default.

Middleware Refactor

  • Replaced the async thunk dispatch (storeStateToUndoRedoHistory) with an inline synchronous middleware that calls next(action) first (so the UI updates immediately), then captures and compresses the pre-mutation state snapshot. Eliminates a Redux dispatch round-trip on every undoable action.

Compression Optimizations

  • Dead-weight field stripping (~20–40% size reduction): Strips immutable/transient fields before compression (workflow.originalDefinition, workflow.runInstance, operations.loadStatus, operations.errors, settings.expandedSections, connections.loading, etc.). Restored from live state on undo/redo.
  • Diff-based per-slice compression (~80–90% reduction in compression time): Leverages Immer's reference equality — unchanged slices reuse cached Uint8Array bytes. Only the 1–2 slices that actually changed get JSON.stringify + deflate. State history items now store a CompressedSliceMap (per-slice Uint8Arrays) instead of a single blob.

Bug Fixes

  • notesSlice.initialState not exported: Added export so the mock root state can import it for tests.

Compression Performance

Metric Before After
Data compressed per snapshot Entire 10-slice state (every time) Only 1–2 changed slices (~10–20% of data)
Compression CPU time deflate over full JSON deflate over only changed slices + stripped fields
Memory per snapshot One large Uint8Array Shared Uint8Array refs for unchanged slices across history entries
Decompression inflate one blob inflate only stored slices; unchanged slices fall back to live state

Impact of Change

  • Users: Ctrl+Z / Ctrl+Y now work in the designer canvas. Undo/Redo added to the VS Code command bar overflow menu. Both disabled in read-only/monitoring mode.
  • Hosts: DEFAULT_MAX_STATE_HISTORY_SIZE changed from 020. Set maxStateHistorySize: 0 to explicitly disable. Uses ?? so 0 is respected.
  • Developers: Middleware is now synchronous (action-first, inline compression). StateHistoryItem.compressedStateStateHistoryItem.compressedSlices. New util functions: getCompressedSlicesFromRootState, getRootStateFromCompressedSlices, stripSliceForSnapshot, restoreStrippedFields.
  • System: Up to 20 pako-compressed state snapshots stored by default. Per-slice caching means most snapshots only store deltas.

Test Plan

  • Unit tests added/updated (76 tests across 6 test files)
  • E2E tests added/updated
  • Manual testing completed
  • Tested in:

Contributors

@rllyy97

Screenshots/Videos

N/A

Copilot AI review requested due to automatic review settings April 7, 2026 21:08
@rllyy97 rllyy97 added the risk:low Low risk change with minimal impact label Apr 7, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 7, 2026

🤖 AI PR Validation Report

PR Review Results

Thank you for your submission! Here's detailed feedback on your PR title and body compliance:

PR Title

  • Current: perf(DesignerV2): Undo/Redo improvements + enabling
  • Issue: The title is generally clear and uses conventional-commit style, but the phrase + enabling is slightly informal and could be made more descriptive (what is being enabled and where). Also consider including the biggest visible user impact (enabling undo/redo) and the important internal change (compression/middleware) concisely.
  • Recommendation: Use a concise, descriptive title. Example: perf(designer-v2): enable undo/redo, add keyboard shortcuts and optimize state-history compression

⚠️ Commit Type

  • Properly selected: refactor and perf are both checked.
  • Note: Multiple commit types are selected. The template asks to select one. This is not a failing problem, but it is ambiguous — please either keep one primary commit type or add a short note in the PR body explaining why both apply (e.g., "refactor: middleware; perf: compression optimizations").

⚠️ Risk Level

  • Risk label present on the PR: risk:medium and the PR body selected Medium.
  • Assessment: The label in the repo matches the PR body selection (Medium). However, after reviewing the code diff — which changes default host behavior (DEFAULT_MAX_STATE_HISTORY_SIZE 0→20), refactors middleware ordering (action-first), introduces a new compression + caching algorithm, and wires new UI + hotkeys — the scope and potential for user-impacting regressions is significant. I advise raising the risk level to High.
    • Please review the risk label if you agree and update if necessary.

What & Why

  • Current: The body provides a good / thorough explanation: enabling keyboard shortcuts, VS Code command bar buttons, changing DEFAULT_MAX_STATE_HISTORY_SIZE, middleware refactor to synchronous action-first, compression optimizations (per-slice + dead-weight stripping), and notes about bug fix (export for notesSlice.initialState).
  • Issue: None critically missing — this section is well written and maps to the code changes.
  • Recommendation: Consider adding a short “Breaking / behavioral change” subsection calling out the default history size change from 0 to 20 and how hosts can override it (you already mention set maxStateHistorySize: 0 — make it very prominent).

Impact of Change

  • Impact is described and lines up with the changes in the diff.
  • Recommendation: Make the host/ops guidance more explicit in Impact:
    • Users: Undo/Redo keyboard shortcuts + VS Code menu entries + disabled in read-only/monitoring mode (already documented). Good.
    • Developers: Note the middleware ordering change explicitly as a potential source of subtle timing issues or race conditions in code that relied on the old async-thunk dispatch ordering. Suggest adding a short migration note for developers who might rely on the previous behavior.
    • System: Add a short note about memory/performance expectations in production (e.g., worst-case memory with maxStateHistorySize=20, and whether per-slice compression has been load-tested on large workflows).

Test Plan

  • Assessment: Unit tests were added/updated in the diff. I found multiple unit test files added/updated (DesignerCommandBar tests, Designer tests, middleware tests, undoredo tests, etc.). The PR body claims "76 tests across 6 test files" — ensure that number is accurate in the PR description if that figure is important for reviewers. The Unit tests check behavior for: menu items, hotkeys registration, middleware action-first behavior, compression capture, and undo/redo actions.
  • Recommendation: Consider adding an E2E or integration smoke test covering: a typical editing session where the user makes multiple edits, uses undo/redo, and asserts that state is restored and UI panel selections are properly restored. If you cannot add E2E tests now, explain why and where manual testing covered the gaps.

Contributors

  • Assessment: @rllyy97 credited in Contributors. Good.
  • Recommendation: If others reviewed or provided design/PM input, optionally list them to make credit explicit.

⚠️ Screenshots/Videos

  • Assessment: N/A — this is primarily a behavioral/engine change and UI additions (menu items + hotkeys) are small. Screenshots are optional.
  • Recommendation: Optional: add a short GIF showing the undo hotkey and the command bar menu undo/redo behavior to make it easier for non-dev reviewers to validate.

Summary Table

Section Status Recommendation
Title Make title slightly more descriptive (see example).
Commit Type ⚠️ Explain why both refactor and perf are selected or pick one primary type.
Risk Level ⚠️ Repo label = risk:medium, but advised risk = High — please re-evaluate.
What & Why Good detail. Add an explicit "breaking behavior" note for the default history-size change.
Impact of Change Add explicit dev migration note about middleware ordering and memory expectations.
Test Plan Unit tests present. Consider adding E2E/integration or explain manual coverage.
Contributors Good. Optionally list additional reviewers/contributors.
Screenshots/Videos ⚠️ Optional; consider a short GIF for easier review.

Final notes and action items

  • Advised risk: High. The PR currently has risk:medium and the body selects Medium. Because this PR changes default runtime behavior (DEFAULT_MAX_STATE_HISTORY_SIZE from 0→20), refactors the middleware ordering to action-first (which can change the timing of side effects), and introduces a new compression/caching layer for undo history, I recommend updating the risk label to risk:high or explicitly documenting why you believe Medium is sufficient. Please update the PR labels if you accept this advice.
  • Please update the Commit Type to a single primary type or add a short note in the PR explaining that both refactor and perf apply (which parts are refactor vs perf). This reduces ambiguity for release notes and changelogs.
  • Emphasize the behavioral change in the PR summary and release notes about the default history size (20) and how to disable it with maxStateHistorySize: 0. This is a user-visible default change that hosts and integrators need to be aware of.
  • Add either an E2E/integration test or an explicit manual testing checklist (e.g., steps to reproduce undo/redo with panel state restored, memory profiling notes, and what was verified) to reassure reviewers that cross-slice restore works under realistic conditions.
  • Verify the numeric claims in the PR body ("76 tests across 6 test files") match the actual updated tests in the diff; update the wording if the numbers differ.

Please update the PR title/body/labels as recommended above. Once you've updated the risk label and clarified the commit type and testing coverage (or added an E2E), this PR should be in good shape for a deeper code review. Thanks for the detailed write-up and tests — the change is valuable, but because it affects core behavior I'm advising higher risk and extra attention during review.


Last updated: Tue, 07 Apr 2026 22:10:12 GMT

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Enables usable undo/redo in DesignerV2 by wiring keyboard shortcuts and VS Code UI triggers, and by making state history non-empty by default while refactoring the undo/redo history middleware ordering.

Changes:

  • Added Ctrl/Cmd+Z and Ctrl/Cmd+Y (incl. Shift+Z) hotkeys to dispatch undo/redo actions in DesignerV2.
  • Added Undo/Redo items to the VS Code designer command bar overflow menu with localization strings.
  • Increased default undo/redo state history size from 0 to 20 and refactored middleware to process actions before persisting history snapshots.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
Localize/lang/strings.json Adds localized string entries for Undo/Redo labels.
libs/designer-v2/src/lib/ui/Designer.tsx Registers undo/redo hotkeys gated by read-only state and canUndo/canRedo selectors.
libs/designer-v2/src/lib/core/utils/middleware.ts Refactors history-saving middleware to capture pre-state, run next(action) first, then persist snapshot.
libs/designer-v2/src/lib/core/utils/test/middleware.spec.ts Updates/expands unit tests for the refactored middleware behavior and ordering.
libs/designer-v2/src/lib/core/state/designerOptions/designerOptionsInterfaces.ts Updates documentation comment to reflect new default history size.
libs/designer-v2/src/lib/common/constants.ts Changes DEFAULT_MAX_STATE_HISTORY_SIZE from 0 to 20.
apps/vs-code-react/src/intl/messages.ts Adds UNDO/REDO message definitions for VS Code React UI.
apps/vs-code-react/src/app/designer/DesignerCommandBar/indexV2.tsx Adds Undo/Redo overflow menu items and icons.
apps/Standalone/src/designer/state/workflowLoadingSlice.ts Updates Standalone hostOptions default maxStateHistorySize to 20.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 7, 2026

📊 Coverage Check

The following changed files need attention:

⚠️ libs/designer-v2/src/lib/core/state/notes/notesSlice.ts - 24% covered (needs improvement)
⚠️ apps/vs-code-react/src/app/designer/DesignerCommandBar/indexV2.tsx - 51% covered (needs improvement)
⚠️ libs/designer-v2/src/lib/ui/Designer.tsx - 79% covered (needs improvement)

Please add tests for the uncovered files before merging.

@rllyy97 rllyy97 added risk:medium Medium risk change with potential impact and removed risk:low Low risk change with minimal impact labels Apr 7, 2026
@rllyy97 rllyy97 added the Performance Performance related issues label Apr 7, 2026
@rllyy97 rllyy97 changed the title refactor(DesignerV2): Undo/Redo improvements + enabling perf(DesignerV2): Undo/Redo improvements + enabling Apr 7, 2026
@rllyy97 rllyy97 enabled auto-merge (squash) April 7, 2026 22:39
@rllyy97 rllyy97 merged commit 4394679 into main Apr 7, 2026
15 of 16 checks passed
@rllyy97 rllyy97 deleted the riley/undo-redo-improvements branch April 7, 2026 22:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Performance Performance related issues pr-validated risk:medium Medium risk change with potential impact

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants