Repository navigation
[lexical-html][lexical-rich-text][lexical-website] Docs: clarify DOMImportExtension rule evaluation order - #9089
Merged
etrepum merged 1 commit intoAug 23, 2026
Conversation
…te: clarify DOMImportExtension rule evaluation order
## Description
The docs for `DOMImportExtension` described rule precedence as "the one
registered LATER wins", which reads as if the `rules` array were walked
back to front. It isn't: `config.rules` is one flat list dispatched
front to back, and "later wins" is a property of how the list is
*assembled*, not of how it is *read*. The two ideas were conflated in
the prose, in `DOMImportConfig`'s JSDoc, and in the `importDOM`
migration table.
Rewritten to separate the two mechanisms:
- **Evaluation** — for a given node the dispatcher visits every matching
rule in list order, and the first one that returns without calling
`$next()` decides the outcome. Earlier entry = higher priority. There
is no numeric priority.
- **Composition** — `mergeConfig` prepends each contribution, and
configs merge in dependency order, so each contributor's array stays
contiguous in its own order while the chunks run most-dependent first.
An extension's rules therefore outrank its dependencies', config
passed straight to `buildEditorFromExtensions` outranks every
extension's, and `DefaultHoistRule` (the base config) is always last.
- Added a caution that the relative order of two extensions where
neither depends on the other falls out of the topological sort and is
not an API guarantee — depend on the extension you mean to override.
The `preprocess` docs had two claims that were the wrong way round: the
stack is run from its END, so per-call preprocessors run BEFORE the
configured ones (not after), and an extension's preprocessors run before
its dependencies' rather than "in dependency order". The
`$inlineStylesFromStyleSheets` snippet's array was ordered so that it did
the opposite of what its comment promised. All corrected, with a new
"Preprocess order" section explaining that `preprocess` composes in the
opposite array direction from `rules` but arrives at the same precedence.
Also corrected two stale comments in `@lexical/rich-text`:
`RichTextImportRules`' "the Google-Docs rules are registered last
(highest priority)" — they are last in that array, which is the lowest
priority within it; what puts them ahead of `CoreImportRules` is that
the whole array is prepended — and `ShadowRootQuoteRule`'s opt-in
instructions, which now show where to contribute it from.
Three tests pin the composition order the docs now describe. No runtime
or API change.
## Test plan
### Before
The composition order was undocumented and untested; the ordering tests
did not exist, and the one test that touched priority was named for the
behavior the docs got wrong:
```
$ npx vitest run packages/lexical-html/src/__tests__/unit/DOMImportExtension.test.ts \
packages/lexical-html/src/__tests__/unit/DOMPreprocess.test.ts --reporter=verbose
✓ ... > rule priority: later-registered rule runs first; can call $next() 10ms
Tests 30 passed (30)
```
(The test's own `rules` array has the winning rule FIRST, so it was
demonstrating the opposite of its name.)
### After
```
$ npx vitest run packages/lexical-html/src/__tests__/unit/DOMImportExtension.test.ts \
packages/lexical-html/src/__tests__/unit/DOMPreprocess.test.ts --reporter=verbose
✓ ... > preprocessors contributed by dependents run before their dependencies 15ms
✓ ... > rule priority: the earlier entry in `rules` runs first; can call $next() 10ms
✓ ... > rules contributed by dependents outrank their dependencies 8ms
✓ ... > among sibling dependencies, the later-listed one outranks 7ms
Tests 33 passed (33)
```
Full `@lexical/html` + `@lexical/rich-text` unit suites, and the repo
checks:
```
$ npx vitest run packages/lexical-html/src/__tests__/unit packages/lexical-rich-text/src/__tests__/unit
Test Files 27 passed (27)
Tests 237 passed (237)
$ npx tsc --noEmit -p .
(no output)
$ npx eslint packages/lexical-html/src packages/lexical-rich-text/src
(no output)
$ npx prettier --check <changed files>
Checking formatting...
All matched files use Prettier code style!
```
E2E and browser-mode suites were not exercised: this change is
documentation, JSDoc, and unit tests only.
Co-Authored-By: Claude <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
etrepum
marked this pull request as ready for review
August 22, 2026 19:04
etrepum
requested review from
acywatson,
fantactuka,
ivailop7,
potatowagon and
zurfyx
as code owners
August 22, 2026 19:04
zurfyx
approved these changes
Aug 23, 2026
unix-max
pushed a commit
to unix-max/lexical
that referenced
this pull request
Aug 28, 2026
…mportExtension rule evaluation order (meta#9089) Co-authored-by: Claude <[email protected]>
Merged
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The docs for
DOMImportExtensiondescribed rule precedence as "the one registered LATER wins", which wasn't precise because the rules are in-order but the rule array is composed in reverse topological order. This PR is explicit about how the rules array is assembled.Test plan
New unit tests that verify the composition order matches this new documentation