Repository navigation
Conversation
…start RangeSelection.insertNodes keeps a reference to the caret's block while it calls insertParagraph(). HeadingNode.insertNewAfter replaces that block with a paragraph when the caret is at offset 0, so insertNodes went on to insert after a node that had already left the document and Lexical threw invariant basecamp#66 ("Expected node to have a parent"). Dropping a file at the start of a heading lost the file and left the editor inconsistent — a following Backspace then threw invariant basecamp#75. An attachment dropped at the start of a block belongs above that block, so BlockStartNodeInserter places it there instead of splitting the block around the caret. Empty blocks are left to Lexical: they are already a usable insertion point, and inserting above one would strand it. Co-Authored-By: Claude <noreply@anthropic.com>
This branch has not been deployed
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.
Dropping a file with the caret at the very start of a heading throws Lexical invariant #66 ("Expected node to have a parent") and the file is lost. The editor is left inconsistent, so a Backspace straight after throws invariant #75.
RangeSelection.insertNodes keeps a reference to the caret's block while it calls insertParagraph(). HeadingNode.insertNewAfter replaces that block with a paragraph when the caret is at offset 0, so insertNodes goes on to insert after a node that has already left the document.
Lexical fixed this on their side in 0.47.0, by re-resolving firstBlock when it is no longer attached. Lexxy pins ^0.44.0, which under npm's 0.x caret can never reach that. I tried the bump instead of this change: lexical 0.49.0 does fix the crash with no source change, but it fails six existing tests here:
So this adds BlockStartNodeInserter, which places a dropped attachment above the block when the caret sits at its start rather than splitting the block around the caret. Empty blocks are left to Lexical, since they are already a usable insertion point. It puts the attachment in the same place lexical 0.47 does, so it can be dropped whenever the bump happens.
It also moves the block-decorator check out of ListItemNodeInserter into $isBlockDecoratorNode, now that two inserters need it.