Skip to content

[lexical-html][lexical-rich-text][lexical-website] Docs: clarify DOMImportExtension rule evaluation order - #9089

Merged
etrepum merged 1 commit into
meta:mainfrom
etrepum:claude/domimportextension-rule-order-jsl3mp
Aug 23, 2026
Merged

etrepum merged 1 commit into
meta:mainfrom
etrepum:claude/domimportextension-rule-order-jsl3mp

Conversation

@etrepum

@etrepum etrepum commented Aug 22, 2026

Copy link
Copy Markdown
Collaborator

Description

The docs for DOMImportExtension described 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

…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]>
@vercel

vercel Bot commented Aug 22, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview Aug 22, 2026 7:01pm
lexical-playground Ready Ready Preview Aug 22, 2026 7:01pm

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 Aug 22, 2026
@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label Aug 22, 2026
@etrepum
etrepum marked this pull request as ready for review August 22, 2026 19:04
@etrepum
etrepum added this pull request to the merge queue Aug 23, 2026
Merged via the queue into meta:main with commit c5866e5 Aug 23, 2026
48 checks passed
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]>
@etrepum etrepum mentioned this pull request Aug 31, 2026

This branch was successfully deployed

2 active deployments
Preview – lexical — 12a9803d Deployed Aug 22, 2026 by vercel[bot]
Preview – lexical-playground — 12a9803d Deployed Aug 22, 2026 by vercel[bot]
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.

3 participants