Repository navigation
[lexical-website] Documentation Update: show $initialEditorState, not a function passed to createEditor - #9205
Merged
etrepum merged 1 commit intoSep 23, 2026
Conversation
… a function passed to createEditor
## Description
The "suppressing the initial scroll/focus" example in the Selection guide
passes a function to `createEditor`:
```js
const editor = createEditor({
editorState: (editor) => { editor.update(() => { ... }); },
});
```
`CreateEditorArgs.editorState` is typed `EditorState` and is assigned straight
to `editor._pendingEditorState`, so a function is not a type error the reader
can ignore — it breaks the editor. Function initializers are accepted by the
root extension's `$initialEditorState` (and by `@lexical/react`'s
`InitialEditorStateType`), which is what the paragraph immediately above the
snippet already points the reader at.
The snippet also nests an `editor.update()` inside the initializer;
`InitialStateExtension` already invokes it inside an update, and the same page
warns against nested updates a few lines earlier.
## Test plan
Documentation-only change (markdown is excluded from prettier via
`.prettierignore`), so the check is that the snippet uses an API that accepts a
function.
### Before
```
$ sed -n '156,166p' packages/lexical-website/docs/concepts/selection.md
```js
const editor = createEditor({
// ...
editorState: (editor) => {
editor.update(() => {
// ... build your initial nodes ...
$setSelection(null);
});
},
});
```
$ grep -n "editorState?:" packages/lexical/src/LexicalEditor.ts
470: editorState?: EditorState;
```
`createEditor` assigns that value directly (`LexicalEditor.ts:1088-1090`), so a
function never runs.
### After
```
$ sed -n '156,165p' packages/lexical-website/docs/concepts/selection.md
```js
const editor = buildEditorFromExtensions({
name: '[root]',
// ...
$initialEditorState: () => {
// ... build your initial nodes ...
$setSelection(null);
},
});
```
```
Matches how `InitialStateExtension` applies a function initializer — inside its
own `editor.update`, so the callback must not nest another
(`packages/lexical-extension/src/InitialStateExtension.ts:66-69`) — and the
root-extension shape used in the repo's own tests, e.g.
`packages/lexical-extension/src/__tests__/unit/DecoratorTextExtension.test.ts:44-65`.
potatowagon
requested review from
acywatson,
etrepum,
fantactuka,
ivailop7 and
zurfyx
as code owners
September 23, 2026 17:33
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
etrepum
approved these changes
Sep 23, 2026
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 "suppressing the initial scroll/focus" example in the Selection guide
passes a function to
createEditor:CreateEditorArgs.editorStateis typedEditorStateand is assigned straightto
editor._pendingEditorState, so a function is not a type error the readercan ignore — it breaks the editor. Function initializers are accepted by the
root extension's
$initialEditorState(and by@lexical/react'sInitialEditorStateType), which is what the paragraph immediately above thesnippet already points the reader at.
The snippet also nests an
editor.update()inside the initializer;InitialStateExtensionalready invokes it inside an update, and the same pagewarns against nested updates a few lines earlier.
Test plan
Documentation-only change (markdown is excluded from prettier via
.prettierignore), so the check is that the snippet uses an API that accepts afunction.
Before
$ grep -n "editorState?:" packages/lexical/src/LexicalEditor.ts
470: editorState?: EditorState;
$ sed -n '156,165p' packages/lexical-website/docs/concepts/selection.md