Skip to content

fix(toolbar): sync undo and redo availability when controls mount - #987

Open
huyanxius wants to merge 4 commits into
mdx-editor:mainfrom
huyanxius:fix/654-conditional-history-toolbar
Open

huyanxius wants to merge 4 commits into
mdx-editor:mainfrom
huyanxius:fix/654-conditional-history-toolbar

Conversation

@huyanxius

@huyanxius huyanxius commented Oct 2, 2026 •

Copy link
Copy Markdown

When the documented ConditionalContents toolbar replaces UndoRedo with the code-language selector, returning to a paragraph leaves Undo disabled even though Cmd/Ctrl+Z can undo the inserted code block. Initialize the controls from the active editor's history so toolbar Undo and Redo work as soon as the controls remount.

Why

I reproduced this on current main (122347cff8af5e9e1291b52789d22ed3ba0dc2ba) with React 19.2.1: start with an empty editor, insert a code block, focus its code, then click the paragraph below it. Undo remains disabled; Cmd+Z removes the block and enables Redo. The existing focus-time replay does not resolve this case.

CAN_UNDO_COMMAND and CAN_REDO_COMMAND notify listeners about changes; registering a listener does not replay commands emitted while the component was unmounted. UndoRedo previously initialized both flags to false on every mount.

Changes

  • Read the active editor's HistoryExtension state when the effect attaches, respecting disabled or absent history, then retain the existing command subscriptions for subsequent updates.
  • Add unit coverage for conditional remounts with Undo and Redo history, empty/suppressed history, and switching between root, local-history, history-free, and absent editors.
  • Add a small bug-654 example and a browser regression for the actual code block/paragraph/toolbar undo/redo flow.

Verification

  • Regression written and observed failing on unmodified main at the remounted Undo button assertion, before the production change.
  • Rechecked head 17fb56702158bc4d277129d34fec89d87a4c7e70: npm run lint and npm run typecheck passed. The full Vitest suite passed with one worker: 126 passed, 1 skipped, 1 todo, including all 15 focused tests across undo-redo.test.tsx, toolbar.test.tsx, and extension-composer.test.tsx.
  • Actual Chromium reproduction before/after: before, toolbar Undo stays disabled while Cmd+Z works; after, toolbar Undo removes the code block and Redo restores it. Empty-document Undo/Redo remain disabled. No page errors.
  • Library build passed. The packed React 18 consumer's declarations, Vite bundle, and Lexical dependency graph checks passed.
  • The checked-in Playwright/Ladle regression and packed React 18 browser runtime remain unverified in the cloud environment: Ladle stops before page creation with uv_interface_addresses, and Chromium startup fails with socket() failed: Operation not permitted. The isolated Chromium reproduction above is separate from the checked-in Playwright test.
  • git diff --check: passed.

Fixes #654

Upstream CI for the current head is action_required, awaiting approval to run this fork workflow: CI run. The implementation is ready for review; browser CI still needs to run.

Conditional toolbars replace history controls while code blocks have focus.

Exercise history remounts, empty states, editor switches, and the code block browser flow.

Guard toolbar availability and verify that undo and redo still change the document.
UndoRedo can mount after history availability commands have already fired.

Read the active editor history before subscribing to future availability commands.

Restore usable undo and redo controls after conditional toolbar changes.
Issue 654 reports unavailable undo and redo after code block insertion.

Add an empty editor with the documented conditional code language toolbar.

Provide a small reproducible example for manual and browser verification.
The history regression fixture triggered two strict lint diagnostics.

Give the edit helper a block body and narrow paragraph nodes with the Lexical guard.

Preserve the same editor updates and assertions without deprecated type casts.
@huyanxius
huyanxius marked this pull request as ready for review October 3, 2026 05:50

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Undo/Redo navigation tool bar buttons not working after inserting code block

1 participant