[lexical-extension] Bug Fix: Use maybeFromEditor in getPeerDependencyFromEditor#8398
Merged
[lexical-extension] Bug Fix: Use maybeFromEditor in getPeerDependencyFromEditor#8398
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
etrepum
approved these changes
Apr 27, 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
Fixes a crash introduced by #8360, which moved code block escape logic into
CodeNode.insertNewAfter()with a backward-compat fallback that callsgetPeerDependencyFromEditor(). The fallback was intended to gracefully handle editors not built withbuildEditorFromExtensions(), butgetPeerDependencyFromEditoritself calledLexicalBuilder.fromEditor(editor)— which throws when no builder is attached to the editor. This means the fallback path could never be reached, and pressing Enter inside a code block crashed the editor.This affects every editor created with
createEditor()directly, which includes all editors on www today.Call chain before this fix
CodeNode.insertNewAfter()insertNewAftercallsgetPeerDependencyFromEditor(editor, 'LexicalCode')to check ifCodeExtensionis registeredgetPeerDependencyFromEditorcallsLexicalBuilder.fromEditor(editor)fromEditorinternally callsmaybeFromEditor(editor)which returnsundefined(no builder attached)fromEditorseesundefinedand throws: "The given editor was not created with LexicalBuilder"insertNewAfternever gets to evaluate the!check or run the fallback — it has already crashedWith this fix
LexicalBuilder.maybeFromEditor(editor)directly, which returnsundefinedinstead of throwingif (!builder) return undefinedearly-returns gracefullyinsertNewAfter,!undefinedis truthy, so it enters the fallback branch and runs the old code block exit logicThis aligns with the function's own JSDoc, which documents the editor parameter as one that "may have been built using extension" and the return type as
| undefined.Test plan
MLCShortcuts-e2e.jstest that was failing now passespnpm run tsc)