Skip to content

[lexical-react] Chore: Remove confusing return value#7607

Merged
etrepum merged 2 commits intofacebook:mainfrom
eliottvincent:main
Jun 7, 2025
Merged

[lexical-react] Chore: Remove confusing return value#7607
etrepum merged 2 commits intofacebook:mainfrom
eliottvincent:main

Conversation

@eliottvincent
Copy link
Copy Markdown
Contributor

@eliottvincent eliottvincent commented Jun 6, 2025

Description

  • What is the current behavior that you are modifying?
    In the AutoLinkPlugin, specifically in the TOGGLE_LINK_COMMAND handler, a value is returned from a forEach loop, which has no effect, is confusing and doesn't make much sense.
  • What are the behavior or changes that are being added by this PR?
    The return value was removed.

@vercel
Copy link
Copy Markdown

vercel bot commented Jun 6, 2025

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 Jun 7, 2025 1:37pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 7, 2025 1:37pm

@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 Jun 6, 2025
Copy link
Copy Markdown
Collaborator

@etrepum etrepum left a comment

Choose a reason for hiding this comment

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

I think the correct fix may be to remove the return true; - what is the actual behavior that you are trying to fix with this PR?

@eliottvincent
Copy link
Copy Markdown
Contributor Author

I think the correct fix may be to remove the return true; - what is the actual behavior that you are trying to fix with this PR?

Hey @etrepum , we are inside a command handler, so the return value (true / false) actually has a meaning. As of right now, whatever happens in the TOGGLE_LINK_COMMAND handler of AutoLinkPlugin, the return value will always be false, even if the AutoLink node was actually toggled. Meaning that any other command handler for TOGGLE_LINK_COMMAND will trigger afterwards.

@etrepum
Copy link
Copy Markdown
Collaborator

etrepum commented Jun 6, 2025

I understand how command handlers work, but I think that the most appropriate fix for this listener is probably to remove the return statement altogether. It looks like what you're trying to do is fix the code to make sense (you are correct, there is something about this code that doesn't make sense), but not considering what the effect of this listener is supposed to be.

What this command is doing is toggling all link nodes in a selection, there is no clear reason why you would only want it to toggle the first AutoLinkNode and then stop. Returning true would prevent further AutoLinkNodes from being toggled, and also avoid calling any other TOGGLE_LINK_COMMAND listener that was registered at a lower priority or registered after at the same priority.

@etrepum
Copy link
Copy Markdown
Collaborator

etrepum commented Jun 6, 2025

Either way, if this does fix a behavior issue, then we should describe what issue is being fixed and add an e2e test to show that it continues to work as expected.

@eliottvincent
Copy link
Copy Markdown
Contributor Author

eliottvincent commented Jun 7, 2025

You're right, I totally missed the fact that this command could be called on a selection with more than one matching node.
I just removed the return true; which is the correct way of fixing things and avoiding confusion.

Thanks for your feedback!

@etrepum
Copy link
Copy Markdown
Collaborator

etrepum commented Jun 7, 2025

Can you fix up the description of this PR to match the current implementation? Looks good to merge otherwise!

@eliottvincent eliottvincent changed the title [lexical-react] Bug Fix: return value was ignored [lexical-react] Chore: Remove confusing return value Jun 7, 2025
@eliottvincent
Copy link
Copy Markdown
Contributor Author

Done!

@etrepum etrepum added this pull request to the merge queue Jun 7, 2025
Merged via the queue into facebook:main with commit 36493cb Jun 7, 2025
66 of 67 checks passed
@etrepum etrepum mentioned this pull request Jul 3, 2025
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants