fix(lexical-html): $generateHtmlFromNodes should self-establish active-editor scope (back-compat for #8519)#8589
Merged
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
cd54b04 to
987ca6b
Compare
987ca6b to
3c0b537
Compare
3c0b537 to
744f5a6
Compare
…tor scope Back-compat fix for #8519. When called from a legacy editorState.read(cb) scope (without {editor} option), $generateHtmlFromNodes now self-establishes an active-editor scope via editor.update({discrete: true}). This prevents the opaque 'getActiveEditor invariant' throw that consumers hit on upgrade when using the previously-idiomatic legacy pattern. When already in an active editor scope (editor.read/editor.update or editorState.read(cb, {editor})), runs inline with zero overhead.
744f5a6 to
2cc4f47
Compare
Contributor
|
Thanks @potatowagon — will follow up after this lands to extend the same back-compat treatment to |
Collaborator
|
$generateDOMFromRoot and $generateDOMFromNodes are newer functions and don’t need this legacy workaround |
etrepum
reviewed
May 29, 2026
Collaborator
|
I think the best solution is a private LexicalUpdates API like this that we export through the lexical package for internal backwards compat use: /** @internal */
export function $assumeActiveEditor(editor: LexicalEditor): void {
// Throw if called outside of an update
if (getActiveEditorState() !== null && activeEditor === null) {
activeEditor = editor;
}
invariant(
activeEditor === editor,
'The given editor argument does not match $getEditor() in this context. Use editor.getEditorState().read(..., {editor}) if this cross-editor call is intentional.',
);
}Then you would just call |
…compat for editor arguments
etrepum
approved these changes
May 29, 2026
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.
Summary
PR #8519 (commit a6908ba) made
$setTextContentinpackages/lexical/src/nodes/LexicalTextNode.tscall$getEditor()at the top of the function. Because$generateHtmlFromNodeswalksTextNode.createDOM/updateDOM → $setTextContent, it now throws inside any caller that uses the previously-idiomaticeditor.getEditorState().read(cb)scope —getActiveEditor()returns null and the call dies with an opaque "getActiveEditor" invariant error.Since
$generateHtmlFromNodesalready receiveseditoras its first argument, it can self-establish the active-editor scope.Changes
$generateHtmlFromNodes: wraps its body ineditor.read(...), which is a no-op if an active editor scope already exists (nested reads are safe in Lexical).$generateDOMFromNodes: same treatment for consistency.$generateDOMFromRoot: same treatment for consistency.This makes all three export functions work correctly regardless of whether the caller uses:
editor.read(cb)(modern pattern — already sets active editor) ✅editor.getEditorState().read(cb, {editor})(explicit editor option) ✅editor.getEditorState().read(cb)(legacy pattern — does NOT set active editor) ✅ ← previously broken after [Breaking Change][lexical][lexical-html][lexical-selection][lexical-utils][lexical-playground] Feature: Generalize DOMSlot and add DOMRenderExtension override surface #8519Test Plan
Added
LexicalHtmlBackwardCompat.test.tswith three tests:$generateHtmlFromNodes(editor)from insideeditor.getEditorState().read(cb)(legacy pattern) — asserts it returns HTML without throwing.editor.read(cb)(modern pattern) — asserts same behavior.All 84 existing tests in
packages/lexical-htmlcontinue to pass unchanged.