Skip to content

[lexical-website] Documentation Update: correct four claims in the extension lifecycle guide - #9208

Merged
etrepum merged 1 commit into
meta:mainfrom
potatowagon:docs-extensions-lifecycle-claims
Sep 23, 2026
Merged

etrepum merged 1 commit into
meta:mainfrom
potatowagon:docs-extensions-lifecycle-claims

Conversation

@potatowagon

Copy link
Copy Markdown
Contributor

Description

Four statements in extensions/defining-extensions.md do not match
@lexical/extension:

  1. state.getInit() — no such method. The state object exposes
    getInitResult(). (state.getOutput(), named in the same sentence, is
    correct.)
  2. "The build phase happens just before the editor is constructed" — it
    runs after createEditor, which is why it receives a LexicalEditor.
    The type's own doc comment says "Perform any tasks that require a
    LexicalEditor instance, but before registration has taken place".
  3. "the graph between peerDependencies are not restricted. Loops are
    allowed."
    — peer edges are added to the same edge map as dependencies
    and walked by the same topological sort, which asserts on cycles. Two
    extensions that peer-depend on each other and are both present throw at
    build time (repro below). This also contradicts peer-dependencies.md,
    which states the DAG requirement.
  4. The PlainTextExtension excerpt shows dependencies: [DragonExtension];
    it has three.

Test plan

Documentation-only change (markdown is excluded from prettier via
.prettierignore), so the check is that each statement matches source. Claim 3
is the one that is not obvious by reading, so it is verified by running it.

Before

$ grep -n "state.getInit()" packages/lexical-website/docs/extensions/defining-extensions.md
264:the result of `init` or `build` via `state.getInit()` and `state.getOutput()`

$ grep -n "getInitResult\|getOutput" packages/lexical/src/extension-core/types.ts
124:  getInitResult: () => Init;
140:  getOutput: () => Output;

$ grep -n "build phase happens" packages/lexical-website/docs/extensions/defining-extensions.md
222:The build phase happens just before the editor is constructed but after

$ grep -n "Loops are allowed" packages/lexical-website/docs/extensions/defining-extensions.md
134:are not restricted. Loops are allowed.

$ grep -n "dependencies: \[DragonExtension\]" packages/lexical-website/docs/extensions/defining-extensions.md
151:  dependencies: [DragonExtension],

A scratch unit test building two extensions that peer-depend on each other,
both present in the editor — what the current text says is allowed:

const A = defineExtension({name: 'A', peerDependencies: [declarePeerDependency('B')]});
const B = defineExtension({name: 'B', peerDependencies: [declarePeerDependency('A')]});
buildEditorFromExtensions(defineExtension({dependencies: [A, B], name: '[root]'}));
$ npx vitest run packages/lexical-extension/src/__tests__/unit/ScratchPeerLoop.test.ts
ACTUAL ERROR: LexicalBuilder: Circular dependency detected for Extension A from B

(The scratch test was for this verification only and is not part of the diff.)

After

$ grep -n "getInitResult()" packages/lexical-website/docs/extensions/defining-extensions.md
264:the result of `init` or `build` via `state.getInitResult()` and

$ sed -n '222,223p' packages/lexical-website/docs/extensions/defining-extensions.md
The build phase happens after the editor is constructed — it receives the
`LexicalEditor` — but before [register](#register), and after

$ sed -n '133,136p' packages/lexical-website/docs/extensions/defining-extensions.md
Since these are optional and by name, an extension may declare a peer it does
not import. The graph must still be acyclic: peer edges take part in the same
topological sort as `dependencies`, so two extensions that peer-depend on each
other and are both present will fail to build.

$ sed -n '151,155p' packages/lexical-website/docs/extensions/defining-extensions.md
  dependencies: [
    DragonExtension,
    NormalizeInlineElementsExtension,
    NormalizeTripleClickSelectionExtension,
  ],

Sources: packages/lexical/src/extension-core/types.ts:124 and :247-251
(the build doc comment); packages/lexical-extension/src/LexicalBuilder.ts:185-205
(createEditor(...) then extensionRep.build(editor) per extension),
:327 (peer edges via the same addEdge) and :341-356 (the
"Circular dependency detected" invariant in the topological sort);
packages/lexical-plain-text/src/index.ts:454-463.

…tension lifecycle guide

## Description

Four statements in `extensions/defining-extensions.md` do not match
`@lexical/extension`:

1. **`state.getInit()`** — no such method. The state object exposes
   `getInitResult()`. (`state.getOutput()`, named in the same sentence, is
   correct.)
2. **"The build phase happens just before the editor is constructed"** — it
   runs *after* `createEditor`, which is why it receives a `LexicalEditor`.
   The type's own doc comment says "Perform any tasks that require a
   LexicalEditor instance, but before registration has taken place".
3. **"the graph between `peerDependencies` are not restricted. Loops are
   allowed."** — peer edges are added to the same edge map as `dependencies`
   and walked by the same topological sort, which asserts on cycles. Two
   extensions that peer-depend on each other and are both present throw at
   build time (repro below). This also contradicts `peer-dependencies.md`,
   which states the DAG requirement.
4. The `PlainTextExtension` excerpt shows `dependencies: [DragonExtension]`;
   it has three.

## Test plan

Documentation-only change (markdown is excluded from prettier via
`.prettierignore`), so the check is that each statement matches source. Claim 3
is the one that is not obvious by reading, so it is verified by running it.

### Before

```
$ grep -n "state.getInit()" packages/lexical-website/docs/extensions/defining-extensions.md
264:the result of `init` or `build` via `state.getInit()` and `state.getOutput()`

$ grep -n "getInitResult\|getOutput" packages/lexical/src/extension-core/types.ts
124:  getInitResult: () => Init;
140:  getOutput: () => Output;

$ grep -n "build phase happens" packages/lexical-website/docs/extensions/defining-extensions.md
222:The build phase happens just before the editor is constructed but after

$ grep -n "Loops are allowed" packages/lexical-website/docs/extensions/defining-extensions.md
134:are not restricted. Loops are allowed.

$ grep -n "dependencies: \[DragonExtension\]" packages/lexical-website/docs/extensions/defining-extensions.md
151:  dependencies: [DragonExtension],
```

A scratch unit test building two extensions that peer-depend on each other,
both present in the editor — what the current text says is allowed:

```ts
const A = defineExtension({name: 'A', peerDependencies: [declarePeerDependency('B')]});
const B = defineExtension({name: 'B', peerDependencies: [declarePeerDependency('A')]});
buildEditorFromExtensions(defineExtension({dependencies: [A, B], name: '[root]'}));
```

```
$ npx vitest run packages/lexical-extension/src/__tests__/unit/ScratchPeerLoop.test.ts
ACTUAL ERROR: LexicalBuilder: Circular dependency detected for Extension A from B
```

(The scratch test was for this verification only and is not part of the diff.)

### After

```
$ grep -n "getInitResult()" packages/lexical-website/docs/extensions/defining-extensions.md
264:the result of `init` or `build` via `state.getInitResult()` and

$ sed -n '222,223p' packages/lexical-website/docs/extensions/defining-extensions.md
The build phase happens after the editor is constructed — it receives the
`LexicalEditor` — but before [register](#register), and after

$ sed -n '133,136p' packages/lexical-website/docs/extensions/defining-extensions.md
Since these are optional and by name, an extension may declare a peer it does
not import. The graph must still be acyclic: peer edges take part in the same
topological sort as `dependencies`, so two extensions that peer-depend on each
other and are both present will fail to build.

$ sed -n '151,155p' packages/lexical-website/docs/extensions/defining-extensions.md
  dependencies: [
    DragonExtension,
    NormalizeInlineElementsExtension,
    NormalizeTripleClickSelectionExtension,
  ],
```

Sources: `packages/lexical/src/extension-core/types.ts:124` and `:247-251`
(the `build` doc comment); `packages/lexical-extension/src/LexicalBuilder.ts:185-205`
(`createEditor(...)` then `extensionRep.build(editor)` per extension),
`:327` (peer edges via the same `addEdge`) and `:341-356` (the
"Circular dependency detected" invariant in the topological sort);
`packages/lexical-plain-text/src/index.ts:454-463`.
@vercel

vercel Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
lexical Ready Ready Preview Sep 23, 2026 5:48pm UTC
lexical-playground Ready Ready Preview Sep 23, 2026 5:48pm UTC

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 Sep 23, 2026
@etrepum
etrepum added this pull request to the merge queue Sep 23, 2026
Merged via the queue into meta:main with commit 51b8079 Sep 23, 2026
42 checks passed
@etrepum etrepum mentioned this pull request Sep 28, 2026

This branch was successfully deployed

2 active deployments
Preview – lexical — 573e1299 Deployed Sep 23, 2026 by vercel[bot]
Preview – lexical-playground — 573e1299 Deployed Sep 23, 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants