Repository navigation
[lexical-link] Bug Fix: TOGGLE_LINK_COMMAND object payload no longer discards the configured attributes - #8985
Merged
Conversation
…discards the configured attributes
## Description
`LinkConfig.attributes` is documented as "The default anchor tag attributes to
use for `TOGGLE_LINK_COMMAND`". The string-payload branch honours it
(`$toggleLink(payload, attributes)`), but the object-payload branch did not:
```ts
const {url, target, rel, title} = payload;
$toggleLink(url, {...attributes, rel, target, title});
```
`LinkAttributes` has exactly three members — `rel`, `target` and `title` — and
all three were destructured out of the payload and then written over the
spread. When the payload omits one, the destructured value is `undefined`, and
an explicit `undefined` still shadows a spread key, so `...attributes` was dead
code: every key it could carry was unconditionally erased.
The result was that the same intent produced two different links depending only
on the payload shape. With `attributes: {rel: 'noopener', target: '_blank',
title: 'Configured title'}` configured:
- `dispatchCommand(TOGGLE_LINK_COMMAND, 'https://lexical.dev/')` produced
`rel="noopener" target="_blank" title="Configured title"`;
- `dispatchCommand(TOGGLE_LINK_COMMAND, {url: 'https://lexical.dev/'})` produced
`rel="noreferrer"` (`$toggleLink`'s own fallback for a missing `rel`) and no
`target` or `title` at all.
Spread the payload's own keys instead, so a key that the payload actually
carries (including an explicit `null`, which clears an attribute) wins and any
key it omits falls back to the configured default. The extension's internal
`PASTE_COMMAND` dispatch already pre-spreads `attributes` into the payload, so
it keeps working unchanged.
## Test plan
Three new cases in `packages/lexical-link/src/__tests__/unit/LinkExtension.test.ts`:
the string payload (passes before and after — it is the reference behaviour),
the object payload, and an object payload that explicitly overrides one
attribute.
### Before
```
$ npx vitest run packages/lexical-link/src/__tests__/unit/LinkExtension.test.ts
FAIL |unit| .../LinkExtension.test.ts > Link > TOGGLE_LINK_COMMAND with configured attributes > applies the configured attributes for an object payload
AssertionError: expected 'noreferrer' to be 'noopener' // Object.is equality
Expected: "noopener"
Received: "noreferrer"
FAIL |unit| .../LinkExtension.test.ts > Link > TOGGLE_LINK_COMMAND with configured attributes > lets the object payload override the configured attributes
AssertionError: expected 'noreferrer' to be 'noopener' // Object.is equality
Expected: "noopener"
Received: "noreferrer"
Test Files 1 failed (1)
Tests 2 failed | 12 passed (14)
```
### After
```
$ npx vitest run packages/lexical-link
Test Files 6 passed (6)
Tests 155 passed (155)
```
LeSingh1
requested review from
acywatson,
etrepum,
fantactuka,
ivailop7,
potatowagon and
zurfyx
as code owners
August 9, 2026 01:03
|
@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
LinkConfig.attributesis documented as "The default anchor tag attributes touse for
TOGGLE_LINK_COMMAND". The string-payload branch honours it(
$toggleLink(payload, attributes)), but the object-payload branch did not:LinkAttributeshas exactly three members —rel,targetandtitle— andall three were destructured out of the payload and then written over the
spread. When the payload omits one, the destructured value is
undefined, andan explicit
undefinedstill shadows a spread key, so...attributeswas deadcode: every key it could carry was unconditionally erased.
The result was that the same intent produced two different links depending only
on the payload shape. With
attributes: {rel: 'noopener', target: '_blank', title: 'Configured title'}configured:dispatchCommand(TOGGLE_LINK_COMMAND, 'https://lexical.dev/')producedrel="noopener" target="_blank" title="Configured title";dispatchCommand(TOGGLE_LINK_COMMAND, {url: 'https://lexical.dev/'})producedrel="noreferrer"($toggleLink's own fallback for a missingrel) and notargetortitleat all.Spread the payload's own keys instead, so a key that the payload actually
carries (including an explicit
null, which clears an attribute) wins and anykey it omits falls back to the configured default. The extension's internal
PASTE_COMMANDdispatch already pre-spreadsattributesinto the payload, soit keeps working unchanged.
Test plan
Three new cases in
packages/lexical-link/src/__tests__/unit/LinkExtension.test.ts:the string payload (passes before and after — it is the reference behaviour),
the object payload, and an object payload that explicitly overrides one
attribute.
Before
After