Repository navigation
[lexical-link] Bug Fix: $toggleLink applies the title attribute for a NodeSelection - #8993
Merged
Merged
Conversation
… NodeSelection
## Description
`$toggleLink` documents its second argument as `{ target, rel, title }` and
destructures all three up front:
```ts
const {target, title} = attributes;
const rel = attributes.rel === undefined ? 'noreferrer' : attributes.rel;
```
The `RangeSelection` path honours all three — it calls `setTitle(title)` on an
existing link and passes `{rel, target, title}` to `$createLinkNode`. The
`NodeSelection` path handles only two of them:
```ts
if (existingLink) {
existingLink.setURL(url);
if (target !== undefined) { existingLink.setTarget(target); }
if (rel !== undefined) { existingLink.setRel(rel); }
// title is never applied
} else {
const linkNode = $createLinkNode(url, {rel, target}); // title omitted
...
}
```
So `title` was silently dropped whenever the selection was a `NodeSelection` —
which is what you have after clicking a decorator node such as an image, a
video embed or a horizontal rule, the exact case where a link tooltip is most
useful. The same call with a text (range) selection produced `title="…"`; with
a node selection it produced no `title` at all.
Apply `title` in both branches, using the same `!== undefined` guard the
sibling `target`/`rel` lines use, so omitting it still leaves an existing
title untouched.
## Test plan
Three new cases in
`packages/lexical-link/src/__tests__/unit/LexicalLinkNode.test.ts`: creating a
link, updating an existing one, and confirming that omitting `title` does not
clear a title already on the node. Each also asserts `url`/`rel`/`target`, so
the two attributes that already worked stay pinned.
### Before
```
$ npx vitest run packages/lexical-link/src/__tests__/unit/LexicalLinkNode.test.ts
× applies the title when creating a link 7ms
× applies the title when updating an existing link 2ms
× leaves an existing title alone when none is supplied 2ms
⎯⎯⎯⎯⎯⎯⎯ Failed Tests 3 ⎯⎯⎯⎯⎯⎯⎯
AssertionError: expected null to be 'Lexical' // Object.is equality
AssertionError: expected null to be 'Second' // Object.is equality
AssertionError: expected null to be 'Kept' // Object.is equality
Tests 3 failed | 71 passed (74)
```
### After
```
$ npx vitest run packages/lexical-link packages/lexical-playground
Test Files 23 passed (23)
Tests 426 passed (426)
```
LeSingh1
requested review from
acywatson,
etrepum,
fantactuka,
ivailop7,
potatowagon and
zurfyx
as code owners
August 9, 2026 01:41
|
@LeSingh1 is attempting to deploy a commit to the Meta Open Source Team on Vercel. A member of the Team first needs to authorize it. |
etrepum
approved these changes
Aug 9, 2026
Merged
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.
Description
$toggleLinkdocuments its second argument as{ target, rel, title }anddestructures all three up front:
The
RangeSelectionpath honours all three — it callssetTitle(title)on anexisting link and passes
{rel, target, title}to$createLinkNode. TheNodeSelectionpath handles only two of them:So
titlewas silently dropped whenever the selection was aNodeSelection—which is what you have after clicking a decorator node such as an image, a
video embed or a horizontal rule, the exact case where a link tooltip is most
useful. The same call with a text (range) selection produced
title="…"; witha node selection it produced no
titleat all.Apply
titlein both branches, using the same!== undefinedguard thesibling
target/rellines use, so omitting it still leaves an existingtitle untouched.
Test plan
Three new cases in
packages/lexical-link/src/__tests__/unit/LexicalLinkNode.test.ts: creating alink, updating an existing one, and confirming that omitting
titledoes notclear a title already on the node. Each also asserts
url/rel/target, sothe two attributes that already worked stay pinned.
Before
After