[lexical-website][lexical-react] Documentation Update: Clarify editorState null vs undefined and empty-state pitfall#8429
Merged
etrepum merged 1 commit intoApr 30, 2026
Conversation
…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.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
etrepum
approved these changes
Apr 30, 2026
Merged
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
Closes #5079.
LexicalComposer'sinitialConfig.editorStateacceptsnullandundefinedwith intentionally different semantics —nullskips default initialization (used by the collaboration plugin), whileundefinedseeds the root with an empty paragraph. The distinction wasn't documented anywhere, and the related failure mode (setEditorStatethrows 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:
InitialEditorStateTypeand theeditorStatefield ofInitialConfigType. These flow into the generated TypeDoc API page and IDE hover tips.initialConfig.editorStatenote in the editor-state concept doc to enumerate the accepted shapes and call out thenullvsundefineddistinction, including the recommended?? undefinedcoalesce pattern when a loader can returnnullfor new documents.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