Skip to content

[lexical-link] Bug Fix: TOGGLE_LINK_COMMAND object payload no longer discards the configured attributes - #8985

Merged
etrepum merged 1 commit into
meta:mainfrom
LeSingh1:fix/link-toggle-config-attributes
Aug 9, 2026
Merged

etrepum merged 1 commit into
meta:mainfrom
LeSingh1:fix/link-toggle-config-attributes

Conversation

@LeSingh1

@LeSingh1 LeSingh1 commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

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:

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)

…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)
```
@vercel

vercel Bot commented Aug 9, 2026

Copy link
Copy Markdown

@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.

@meta-cla meta-cla 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 9, 2026
@etrepum
etrepum added this pull request to the merge queue Aug 9, 2026
Merged via the queue into meta:main with commit cf1582e Aug 9, 2026
44 checks passed
@etrepum etrepum mentioned this pull request Aug 31, 2026
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.

2 participants