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: Fix decorator selection regression with short-circuiting #6508

Merged
merged 2 commits into from
Aug 11, 2024

Conversation

etrepum
Copy link
Collaborator

@etrepum etrepum commented Aug 10, 2024

Description

The fix in #5948 introduced a crashing regression because the logic doesn't short-circuit when an empty element is encountered.

Closes #6506

Test plan

Before

Crash happens after these conditions:

  • Clear playground
  • Insert blank line (creating empty paragraph node)
  • Insert image (in a second paragraph)
  • Select all

sample url - must select all after clicking this

example exception
Error rendering tree: Expected node 47 to have a last child.

Stack:
Error: Expected node 47 to have a last child.
    at Il.getLastChildOrThrow (https://playground.lexical.dev/assets/main-CGFr7rm0.js:51:28219)
    at _a.isSelected (https://playground.lexical.dev/assets/main-CGFr7rm0.js:45:5077)
    at https://playground.lexical.dev/assets/main-CGFr7rm0.js:347:106
    at https://playground.lexical.dev/assets/main-CGFr7rm0.js:362:162
    at Array.forEach (<anonymous>)
    at MC (https://playground.lexical.dev/assets/main-CGFr7rm0.js:362:146)
    at https://playground.lexical.dev/assets/main-CGFr7rm0.js:362:224
    at Array.forEach (<anonymous>)
    at MC (https://playground.lexical.dev/assets/main-CGFr7rm0.js:362:146)
    at https://playground.lexical.dev/assets/main-CGFr7rm0.js:347:42

After

Doesn't crash, has more test coverage

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
…heck with proper short-circuiting
Copy link

vercel bot commented Aug 10, 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 Aug 10, 2024 6:31am
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 10, 2024 6:31am

@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 Aug 10, 2024
Copy link

github-actions bot commented Aug 10, 2024

size-limit report 📦

Path Size
lexical - cjs 29.25 KB (0%)
lexical - esm 29.11 KB (0%)
@lexical/rich-text - cjs 37.66 KB (0%)
@lexical/rich-text - esm 30.9 KB (0%)
@lexical/plain-text - cjs 36.24 KB (0%)
@lexical/plain-text - esm 28.29 KB (0%)
@lexical/react - cjs 39.49 KB (-0.08% 🔽)
@lexical/react - esm 32.39 KB (0%)

const firstElement = firstPoint.getNode() as ElementNode;
if (
firstPoint.offset === firstElement.getChildrenSize() &&
firstElement.is(parentNode) &&
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's imperative that this check is before the next one for short circuiting reasons

Comment on lines +298 to +300
const firstPoint = targetSelection.isBackward()
? targetSelection.focus
: targetSelection.anchor;
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 gets rid of half the code

@etrepum
Copy link
Collaborator Author

etrepum commented Aug 10, 2024

Moving back to draft to investigate e2e test failures

@etrepum etrepum marked this pull request as ready for review August 10, 2024 06:44
@etrepum
Copy link
Collaborator Author

etrepum commented Aug 10, 2024

I can't get any of those e2e test to fail locally, I think they might be flaky

edit: reran the tests, the flaky failure was in packages/lexical-playground/__tests__/e2e/Links.spec.mjs:1960:3

@ivailop7 ivailop7 added the extended-tests Run extended e2e tests on a PR label Aug 11, 2024
@etrepum etrepum added this pull request to the merge queue Aug 11, 2024
Merged via the queue into facebook:main with commit 3f79ca0 Aug 11, 2024
43 checks passed
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: Editor Crash when selecting an empty paragraph with an image
3 participants