Skip to content

[lexical-website] Documentation Update: show $initialEditorState, not a function passed to createEditor - #9205

Merged
etrepum merged 1 commit into
meta:mainfrom
potatowagon:docs-selection-initial-editor-state
Sep 23, 2026
Merged

etrepum merged 1 commit into
meta:mainfrom
potatowagon:docs-selection-initial-editor-state

Conversation

@potatowagon

Copy link
Copy Markdown
Contributor

Description

The "suppressing the initial scroll/focus" example in the Selection guide
passes a function to createEditor:

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

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`.

… 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`.
@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:35pm UTC
lexical-playground Ready Ready Preview Sep 23, 2026 5:35pm 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 64d134f 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 — b31edea7 Deployed Sep 23, 2026 by vercel[bot]
Preview – lexical-playground — b31edea7 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