Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[lexical] Bug Fix: Insertion into inline ElementNode should not crash #6703

Merged
merged 2 commits into from
Oct 5, 2024

Conversation

etrepum
Copy link
Collaborator

@etrepum etrepum commented Oct 4, 2024

Description

Closes #6701

Test plan

Before

Constructing a document where the children of RootNode are inline ElementNode causes a crash on selection.insertNodes(…) (as in paste) because there is an assumption with no runtime invariant that all children of the root are block nodes.

After

A runtime invariant was added to prevent that, and the incorrect type assertions were removed. A unit test is added to cover this particular case.

Copy link

vercel bot commented Oct 4, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lexical ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 5, 2024 0:44am
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 5, 2024 0:44am

@facebook-github-bot facebook-github-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 Oct 4, 2024
Copy link

github-actions bot commented Oct 4, 2024

size-limit report 📦

Path Size
lexical - cjs 29.86 KB (0%)
lexical - esm 29.75 KB (0%)
@lexical/rich-text - cjs 38.45 KB (0%)
@lexical/rich-text - esm 31.58 KB (0%)
@lexical/plain-text - cjs 37.09 KB (0%)
@lexical/plain-text - esm 28.95 KB (0%)
@lexical/react - cjs 40.22 KB (0%)
@lexical/react - esm 32.94 KB (0%)

@@ -1732,7 +1732,7 @@ export function INTERNAL_$isBlock(
export function $getAncestor<NodeType extends LexicalNode = LexicalNode>(
node: LexicalNode,
predicate: (ancestor: LexicalNode) => ancestor is NodeType,
) {
): NodeType | null {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just being a bit more explicit rather than relying on inference, usually it's best practice for exported types to be explicit.

@etrepum etrepum added this pull request to the merge queue Oct 5, 2024
Merged via the queue into facebook:main with commit 04fbcdb Oct 5, 2024
42 of 43 checks passed
@etrepum etrepum deleted the inline-elementnode-insertion branch October 5, 2024 19:50
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. extended-tests Run extended e2e tests on a PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: Pasting into custom inline ElementNode fails
3 participants