Skip to content

[lexical] Feature: COMMAND_PRIORITY_BEFORE_* priorities for last-registered-called-first order#8375

Merged
etrepum merged 7 commits intofacebook:mainfrom
etrepum:command-listener-lifo
Apr 21, 2026
Merged

[lexical] Feature: COMMAND_PRIORITY_BEFORE_* priorities for last-registered-called-first order#8375
etrepum merged 7 commits intofacebook:mainfrom
etrepum:command-listener-lifo

Conversation

@etrepum
Copy link
Copy Markdown
Collaborator

@etrepum etrepum commented Apr 20, 2026

Description

Command listeners are now called in the following order until a listener returns true:

  • From priority highest to lowest (CRITICAL, HIGH, NORMAL, LOW, EDITOR)
  • All COMMAND_PRIORITY_BEFORE_${priority} listeners, most recently registered first
  • All COMMAND_PRIORITY_${priority} listeners, in registration order

This PR adds support for adding to "both ends" of the listener collection with a deque (double ended queue) type data structure with the following new priorities:

  • COMMAND_PRIORITY_BEFORE_EDITOR
  • COMMAND_PRIORITY_BEFORE_LOW
  • COMMAND_PRIORITY_BEFORE_NORMAL
  • COMMAND_PRIORITY_BEFORE_HIGH
  • COMMAND_PRIORITY_BEFORE_CRITICAL

Generally these new before priorities can be used in place of their respective legacy priority and you will get the desired behavior. There is little reason to use the legacy priorities except to support legacy code that may have subtle ordering dependencies.

New Commands priorities and ordering docs

The original editor.dispatchCommand ordering (highest priority first, then first registered) was counter-productive, a more useful order is highest priority first, then last registered (highest index first). The ideal ordering is almost always for last-registered to be called first.

It was so rarely useful in fact that changing the order globally only broke a single e2e test where the @lexical/rich-text handler for KEY_TAB_COMMAND, KEY_ENTER_COMMAND and KEY_SPACE_COMMAND to reset capitalization (the 'lowercase', 'uppercase', and 'capitalize' formats) was expected to be called even though it is the lowest editor priority. This has been left as-is since we are making an additive change and the existing priorities are not reversed.

Priorities of all existing command registrations have not changed, so this new ordering should not be a breaking change.

Test plan

New unit tests to confirm expected call order and internal representation.

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 20, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview, Comment Apr 21, 2026 3:28am
lexical-playground Ready Ready Preview, Comment Apr 21, 2026 3:28am

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 20, 2026
@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label Apr 20, 2026
@etrepum etrepum marked this pull request as ready for review April 20, 2026 05:31
@etrepum etrepum changed the title [Breaking Change][lexical] Feature: Command listener priorities are now last-registered-called-first [lexical] Feature: COMMAND_PRIORITY_BEFORE_* priorities for last-registered-called-first order Apr 20, 2026
@etrepum etrepum added this pull request to the merge queue Apr 21, 2026
Merged via the queue into facebook:main with commit d244da5 Apr 21, 2026
38 checks passed
levensta pushed a commit to levensta/lexical that referenced this pull request Apr 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. extended-tests Run extended e2e tests on a PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants