Skip to content

[lexical-website][lexical-react] Documentation Update: Clarify editorState null vs undefined and empty-state pitfall#8429

Merged
etrepum merged 1 commit into
facebook:mainfrom
markselby9:docs-clarify-editorstate-null-vs-undefined
Apr 30, 2026
Merged

[lexical-website][lexical-react] Documentation Update: Clarify editorState null vs undefined and empty-state pitfall#8429
etrepum merged 1 commit into
facebook:mainfrom
markselby9:docs-clarify-editorstate-null-vs-undefined

Conversation

@markselby9

Copy link
Copy Markdown
Contributor

Description

Closes #5079.

LexicalComposer's initialConfig.editorState accepts null and undefined with intentionally different semantics — null skips default initialization (used by the collaboration plugin), while undefined seeds the root with an empty paragraph. The distinction wasn't documented anywhere, and the related failure mode (setEditorState throws on a state whose root is the only node and there is no selection) wasn't mentioned either, so users hit the cryptic "the editor state is empty..." error after persisting and reloading a never-modified editor.

This PR:

  • Adds TSDoc to InitialEditorStateType and the editorState field of InitialConfigType. These flow into the generated TypeDoc API page and IDE hover tips.
  • Expands the existing initialConfig.editorState note in the editor-state concept doc to enumerate the accepted shapes and call out the null vs undefined distinction, including the recommended ?? undefined coalesce pattern when a loader can return null for new documents.
  • Adds a `:::warning` admonition next to the `setEditorState` example explaining when it throws (referencing `EditorState.isEmpty()` directly) and how to avoid the empty-state pitfall.

Test plan

Before

The bug at #5079 (and the maintainer reply: "null means to not initialize the editor at all, whereas an undefined value gives the default. The former is used for collaborative editing scenarios.") — none of this was reflected in the docs or the type definition.

After

  • `pnpm run prettier`, `pnpm run lint`, `pnpm run tsc` all pass.
  • `pnpm -C packages/lexical-website run build` succeeds; the new TSDoc renders correctly on the generated `@lexical/react/LexicalComposer` API page.
…State null vs undefined and empty-state pitfall

Closes facebook#5079.

`LexicalComposer`'s `initialConfig.editorState` accepts `null` and
`undefined` with intentionally different semantics — `null` skips default
initialization (used by the collaboration plugin), while `undefined`
seeds the root with an empty paragraph. The distinction wasn't
documented anywhere, and the related failure mode (`setEditorState`
throws on a state whose root has only the root node and no selection)
wasn't mentioned either, so users hit the cryptic "the editor state is
empty..." error after persisting and reloading a never-modified editor.

This change adds TSDoc to `InitialEditorStateType` and the `editorState`
field of `InitialConfigType`, expands the existing "used only once" note
in the editor-state concept doc into an enumeration of accepted shapes
with the null vs undefined distinction, and adds a `:::warning`
admonition next to the `setEditorState` example explaining when it
throws and how to avoid the empty-state pitfall.
@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 Apr 30, 2026
@vercel

vercel Bot commented Apr 30, 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, Comment Apr 30, 2026 7:20am
lexical-playground Ready Ready Preview, Comment Apr 30, 2026 7:20am

Request Review

@etrepum etrepum added this pull request to the merge queue Apr 30, 2026
Merged via the queue into facebook:main with commit 71e3b6b Apr 30, 2026
72 of 73 checks passed
@etrepum etrepum mentioned this pull request May 28, 2026
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.

2 participants