Skip to content

[lexical-link] Bug Fix: Configure link navigation and isolate nested editors - #9360

Merged
etrepum merged 4 commits into
meta:mainfrom
maximilliangrand:fix/clickable-link-owner-window
Oct 19, 2026
Merged

etrepum merged 4 commits into
meta:mainfrom
maximilliangrand:fix/clickable-link-owner-window

Conversation

@maximilliangrand

@maximilliangrand maximilliangrand commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Description

ClickableLinkExtension always opens links using the global window, even when its editor is mounted inside an iframe. Add a configurable getWindow(editor) callback to the extension, preserving the global window as the default. Applications can return the editor root's owning window to navigate within its iframe, or null to leave the click unhandled. The extension's TypeScript and Flow definitions include the option. The legacy React plugin keeps its existing interface.

The extension supplies a concrete default callback, so its configuration and output signal always contain a function. Existing direct registerClickableLink callers that supply only disabled and newTab signals retain the global-window default.

Also restrict each click handler to its own editor. A nested link currently bubbles into the parent's handler and opens twice, potentially using different newTab settings; the parent also handles links when the nested extension is disabled. This includes the nested-editor fix from #9361.

Test plan

Before

With the original 11 browser regressions and the implementation from main:

VITEST_BROWSER=chromium pnpm exec vitest run --project browser packages/lexical-link/src/__tests__/browser/ClickableLinkIframe.test.ts packages/lexical-link/src/__tests__/browser/ClickableLinkNestedEditor.test.ts

Test Files  2 failed (2)
     Tests  9 failed | 2 passed (11)

The middle-click and new-tab default-window controls pass. Custom iframe windows, null resolvers, runtime window changes, and nested-editor ownership fail.

After

VITEST_BROWSER=chromium,firefox,webkit pnpm exec vitest run --project browser packages/lexical-link/src/__tests__/browser/ClickableLinkIframe.test.ts packages/lexical-link/src/__tests__/browser/ClickableLinkNestedEditor.test.ts

Test Files  6 passed (6)
     Tests  36 passed (36)

pnpm exec vitest run --project unit packages/lexical-link/src/__tests__/unit

Test Files  12 passed (12)
     Tests  280 passed (280)

pnpm exec tsc --noEmit
pnpm exec tsc -p tsconfig.test.json --noEmit
pnpm exec eslint packages/lexical-link/src/ClickableLinkExtension.ts packages/lexical-link/src/__tests__/browser/ClickableLinkIframe.test.ts packages/lexical-link/src/__tests__/browser/ClickableLinkNestedEditor.test.ts packages/lexical-react/src/LexicalClickableLinkPlugin.tsx
pnpm run flow

Running Flow...
Found 0 errors

The latest validation used Node 25.9.0 and the repository's installed tools; the commands above show their pnpm equivalents. TypeScript and ESLint exit successfully without diagnostics. Formatting and git diff --check pass.

Browser tests use real iframe/nested editor roots and spy on window.open; they verify routing, targets, noopener, cancellation, changing/resetting the window resolver at runtime, and direct registration without a window signal. Focused source tree-shaking checks for ClickableLinkExtension and LexicalClickableLinkPlugin also pass. The full monorepo and playground E2E suites were not run locally.

## Description

When Lexical runs in a parent page but the editor root is inside an iframe, `registerClickableLink` calls the parent's `window.open`. A normal link with `_self` consequently navigates the host page rather than the editor frame.

Use the clicked node's owning window for navigation. Middle clicks and `newTab: true` keep their `_blank`/`noopener` behavior. This shared handler also serves `ClickableLinkPlugin` in React.

## Test plan

### Before

On unchanged main, with the new browser regression:

```text
node node_modules/vitest/vitest.mjs run --project browser packages/lexical-link/src/__tests__/browser/ClickableLinkIframe.test.ts

 Test Files  1 failed (1)
      Tests  3 failed (3)
```

All three cases call the parent window instead of the iframe window.

### After

Same tests with `VITEST_BROWSER=chromium,webkit`:

```text
 Test Files  2 passed (2)
      Tests  6 passed (6)
```

Existing `lexical-link` unit suite:

```text
 Test Files  12 passed (12)
      Tests  280 passed (280)
```

Source and test TypeScript checks, ESLint on the changed files, Prettier, and `git diff --check` pass. Tested on macOS with Node 26.7.0. Browser tests spy on both windows' `open` methods and verify the target, `noopener`, and cancellation of default navigation; they do not actually navigate away. Firefox and the full monorepo suite were not run.

AI assistance: Codex authored and locally validated the patch and tests.
@vercel

vercel Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
lexical Ready Ready Preview Oct 19, 2026 4:50pm UTC
lexical-playground Ready Ready Preview Oct 19, 2026 4:50pm UTC

Request Review

@etrepum etrepum left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think this behavior is intentional, perhaps the right solution here would be to add configuration to the extension to get the window which defaults to the global window

…k navigation and isolate nested editors

## Description

`ClickableLinkExtension` always opens links using the global window, even when its editor is mounted inside an iframe. Add an optional `getWindow(editor)` callback to the extension and `ClickableLinkPlugin`, preserving the global window as the default. Applications can return the editor root's owning window to navigate within its iframe, or `null` to leave the click unhandled. TypeScript, Flow, and the plugin documentation include the option.

Also restrict each click handler to its own editor. A nested link currently bubbles into the parent's handler and opens twice, potentially using different `newTab` settings; the parent also handles links when the nested extension is disabled. This includes the nested-editor fix from meta#9361.

## Test plan

### Before

With the new browser regressions and the implementation from `main`:

```text
VITEST_BROWSER=chromium pnpm exec vitest run --project browser packages/lexical-link/src/__tests__/browser/ClickableLinkIframe.test.ts packages/lexical-link/src/__tests__/browser/ClickableLinkNestedEditor.test.ts

Test Files  2 failed (2)
     Tests  9 failed | 2 passed (11)
```

The middle-click and new-tab default-window controls pass. Custom iframe windows, null resolvers, runtime window changes, and nested-editor ownership fail.

### After

```text
VITEST_BROWSER=chromium,firefox,webkit pnpm exec vitest run --project browser packages/lexical-link/src/__tests__/browser/ClickableLinkIframe.test.ts packages/lexical-link/src/__tests__/browser/ClickableLinkNestedEditor.test.ts

Test Files  6 passed (6)
     Tests  33 passed (33)

pnpm exec vitest run --project unit packages/lexical-link/src/__tests__/unit

Test Files  12 passed (12)
     Tests  280 passed (280)

pnpm exec tsc --noEmit
pnpm exec tsc -p tsconfig.test.json --noEmit
pnpm exec eslint packages/lexical-link/src/ClickableLinkExtension.ts packages/lexical-link/src/__tests__/browser/ClickableLinkIframe.test.ts packages/lexical-link/src/__tests__/browser/ClickableLinkNestedEditor.test.ts packages/lexical-react/src/LexicalClickableLinkPlugin.tsx
pnpm run flow

Running Flow...
Found 0 errors
```

Executed with Node 26.7.0 and the repository's installed tools; the commands above show their pnpm equivalents. TypeScript and ESLint exit successfully without diagnostics. Formatting and `git diff --check` pass.

Browser tests use real iframe/nested editor roots and spy on `window.open`; they verify routing, targets, `noopener`, cancellation, and changing/resetting the window resolver at runtime without navigating away. The full monorepo and playground E2E suites were not run locally.
@maximilliangrand maximilliangrand changed the title [lexical-link] Bug Fix: Follow iframe links in their owning window [lexical-link][lexical-react][lexical-website] Bug Fix: Configure link navigation and isolate nested editors Oct 16, 2026

@etrepum etrepum left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this should be cleaned up to use a default getWindow implementation in the configuration to simplify the implementation

export type ClickableLinkConfig = {
newTab: boolean;
disabled: boolean;
getWindow?: (editor: LexicalEditor) => Window | null;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

config types never have optional values, they are all provided by the extension defaults

* Resolve the window used to open links (defaults to the global window).
* Return null to leave the click unhandled.
*/
getWindow?: (editor: LexicalEditor) => Window | null;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
getWindow?: (editor: LexicalEditor) => Window | null;
getWindow: (editor: LexicalEditor) => Window | null;

},
config: safeCast<ClickableLinkConfig>({
disabled: false,
getWindow: undefined,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
getWindow: undefined,
getWindow,

event.metaKey ||
event.ctrlKey ||
urlTarget === '_blank';
const getWindow = stores.getWindow && stores.getWindow.peek();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
const getWindow = stores.getWindow && stores.getWindow.peek();
const getWindow = stores.getWindow.peek();

…resolver

## Description

Provide a concrete getWindow callback in ClickableLinkExtension's default
configuration and reuse it as the React plugin's default. The click handler
can read and invoke a guaranteed callback from its signal.

Keep existing registerClickableLink callers working when they supply only
disabled and newTab signals by providing the default signal at registration.
Update TypeScript and Flow declarations together, and cover direct registration
and restoring the default resolver after a runtime override.

## Test plan

### Before

With the updated browser tests on the previous revision:

```text
VITEST_BROWSER=chromium npx --yes --package=node@26.7.0 -c 'node node_modules/vitest/vitest.mjs run --project browser packages/lexical-link/src/__tests__/browser/ClickableLinkIframe.test.ts packages/lexical-link/src/__tests__/browser/ClickableLinkNestedEditor.test.ts'

Test Files  1 failed | 1 passed (2)
     Tests  1 failed | 11 passed (12)
```

The default resolver signal contains undefined instead of a function. The
direct-registration compatibility control passes.

### After

```text
VITEST_BROWSER=chromium,firefox,webkit npx --yes --package=node@26.7.0 -c 'node node_modules/vitest/vitest.mjs run --project browser packages/lexical-link/src/__tests__/browser/ClickableLinkIframe.test.ts packages/lexical-link/src/__tests__/browser/ClickableLinkNestedEditor.test.ts'

Test Files  6 passed (6)
     Tests  36 passed (36)

npx --yes --package=node@26.7.0 -c 'node node_modules/vitest/vitest.mjs run --project unit packages/lexical-link/src/__tests__/unit'

Test Files  12 passed (12)
     Tests  280 passed (280)

npx --yes --package=node@26.7.0 -c 'node node_modules/vitest/vitest.mjs run --project scripts-unit scripts/__tests__/unit/treeShakingSource.test.ts -t "ClickableLink"'

Test Files  1 passed (1)
     Tests  2 passed | 338 skipped (340)

npx --yes --package=node@26.7.0 -c 'node node_modules/typescript/bin/tsc --noEmit && node node_modules/typescript/bin/tsc -p tsconfig.test.json --noEmit'

npx --yes --package=node@26.7.0 -c 'node scripts/check-flow-types.mjs'

Running Flow...
Found 0 errors
```

Source and test TypeScript checks exit 0 without diagnostics. Changed-file
ESLint, Prettier and git diff --check pass. The other 338 tree-shaking cases
were excluded by the test-name filter. The full monorepo and local playground
E2E suites were not run.
*
* @returns `null`, this plugin renders no DOM of its own.
*/
export function ClickableLinkPlugin({

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We don't need to change the interface for these legacy plugins, only the extension needs to carry the new functionality

Comment on lines +212 to +225
Links open using the global window by default. For an editor mounted in an
iframe, pass `getWindow` to navigate within that frame instead:

```jsx
<ClickableLinkPlugin
newTab={false}
getWindow={editor => editor.getRootElement()?.ownerDocument.defaultView ?? null}
/>
```

`getWindow` is called for each link click. Returning `null` leaves the click
unhandled. The same option is available on `ClickableLinkExtension`. Each
editor handles its own links; a parent editor does not handle link clicks from
a nested editor.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Let's not update the plugin, people should prefer using the extension. We'll remove the legacy plugin eventually.

…tion on the extension

## Description

Remove the new getWindow prop from the legacy ClickableLinkPlugin and restore its Flow declaration and plugin documentation. Custom link-window selection remains available on ClickableLinkExtension, while the plugin continues to use registerClickableLink's compatible default.

## Test plan

### After

```text
node node_modules/vitest/vitest.mjs run --project unit packages/lexical-link
Test Files  12 passed (12)
     Tests  280 passed (280)

VITEST_BROWSER=chromium,firefox,webkit node node_modules/vitest/vitest.mjs run --project browser packages/lexical-link/src/__tests__/browser/ClickableLinkIframe.test.ts packages/lexical-link/src/__tests__/browser/ClickableLinkNestedEditor.test.ts
Test Files  6 passed (6)
     Tests  36 passed (36)

node scripts/check-flow-types.mjs
Running Flow...
Found 0 errors
```

Source and test TypeScript checks, focused ESLint/Prettier, and git diff --check pass on macOS with Node 25.9.0. The full monorepo and playground E2E suites were not run.
@maximilliangrand maximilliangrand changed the title [lexical-link][lexical-react][lexical-website] Bug Fix: Configure link navigation and isolate nested editors [lexical-link] Bug Fix: Configure link navigation and isolate nested editors Oct 19, 2026
@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label Oct 19, 2026
@etrepum
etrepum added this pull request to the merge queue Oct 19, 2026
Merged via the queue into meta:main with commit 6809a8c Oct 19, 2026
52 checks passed
@zurfyx zurfyx mentioned this pull request Oct 27, 2026
zurfyx added a commit that referenced this pull request Oct 27, 2026
…ed since #9353

## Description

The changesets in this PR covered main up to #9353. Since then, 27 PRs
that change a published package's shipped code have merged without one,
so the v0.53.0 release would list them only under "All changes". This adds
a changeset for each, with a `PR:` line and the author's handle:

- `[breaking]`: #9478 (`@lexical/mdast` table alignment moves out of the
  `mdastTableAlign` NodeState) and #9329 (`reconcileObservedMutation`,
  `@internal`), both with `Migration:` and `Detect:`.
- `[feature]`: #9452, #9421, #9380 (experimental), #9360, #9365.
- `[perf]`: #9349.
- `[fix]`: the remaining 19. #9396, #9392, #9270 and #9360 carry `Verify:`
  because they change observable output.

Website, playground, devtools, CI and internal lint changes need none.

## Test plan

### Before

```
$ git log --format=%s fd661f0..origin/main   # merged since this PR's base
(27 PRs touching published packages' src/flow, none with a changeset)
```

### After

```
$ pnpm run check-changesets
Changeset check passed: 54 pending changeset(s) valid.

$ pnpm run changelog
## v0.53.0 (2026-10-27)
### Breaking changes
- **lexical, @lexical/clipboard, @lexical/selection, @lexical/table**: Let mouse drags select across inline decorators; ... (#9329)
- **@lexical/mdast**: `MdastTableExtension` reads and writes GFM tables, ... (#9478)
- **@lexical/code-core, ...**: Remove the extensions deprecated in v0.52.0 and earlier (#9316)
### Behavior changes
...
```
AlessioGr added a commit to payloadcms/payload that referenced this pull request Oct 28, 2026
_Written with AI_

Upgrades  lexical from `0.52.0` to `0.53.0`.

## Breaking changes

Rich-text data keeps its existing format. No database migration is
needed. Payload's built-in features have been updated, but your own
TypeScript code or custom features may need changes:

- **Node type arguments:** `getParent<T>()`, `getParentOrThrow<T>()`,
`getChildren<T>()`, `getFirstChild<T>()`, `getNextSibling<T>()`,
`$getNodeByKey<T>()` and the rest of that family no longer accept a type
argument. Remove `<T>` and narrow the result with a node guard such as
`$isListItemNode`. Runtime behavior is unchanged.
- **Removed extensions:** `LinkImportExtension`, `ListImportExtension`,
`RichTextImportExtension` and `HorizontalRuleImportExtension`
(deprecated in 0.52) are no longer exported from
`@payloadcms/richtext-lexical/lexical/link`, `/list`, `/rich-text` and
`/html`. Use `LinkExtension`, `ListExtension` and `RichTextExtension`;
for horizontal rules, use `HorizontalRuleExtension` from
`@lexical/extension`.
- **Markdown export:** `convertLexicalToMarkdown` escapes literal
brackets and HTML-like text, for example `[note]` becomes
`&#91;note&#93;`, so it is not parsed back as a link or HTML.
`convertMarkdownToLexical` restores the original text.

## Breaking changes and Payload migrations

Reviewed [0.53.0](https://github.com/meta/lexical/releases/tag/v0.53.0)
and the `CHANGELOG.md` now shipped in the `lexical` package, including
its behavior changes. **Yes** means Payload code needed adaptation;
**No** means no Payload migration was required.

| Breaking change | Required migration in Payload | Changes made |
|
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| ----------------------------- |
---------------------------------------------------------------------------------------------------------------------------------------------------
|
| [Unchecked node type arguments are
removed](meta/lexical#9479) from traversal
and key lookup methods. | Yes | `TableCellResizerPlugin` called
`tableRow.getChildren<TableCellNode>()`. It now uses
`.filter($isTableCellNode)`, matching the upstream playground. |
| [Extensions deprecated in 0.52 are
removed](meta/lexical#9316). | No | Payload
does not use them. They disappear from the `export *` proxies listed
above. |
| [`ElementNode.reconcileObservedMutation` restores the committed
children's DOM](meta/lexical#9329)
(`@internal`). | No | No Payload call sites. |
| [`@lexical/mdast` stores table column alignment as cell paragraph
format](meta/lexical#9478). | No | Payload
does not use `@lexical/mdast`. |
| Behavior: [Markdown export escapes literal
text](meta/lexical#9481). | No | Documented
in the migration guide. MDX round-trip int tests pass unchanged. |
| Behavior: [a read-only `ContentEditable` without an accessible name no
longer renders
`role="textbox"`](meta/lexical#9270). | No |
Payload passes the field label as `aria-label`, so labeled read-only
editors keep the role. |
| Behavior: [`ClickableLinkPlugin` opens new tabs without
`window.opener`](meta/lexical#9303), and
[nested editors handle their own link
clicks](meta/lexical#9360). | No | The link
feature uses `ClickableLinkPlugin` and gets the reverse-tabnabbing fix
automatically. |

Package entry points of every proxied package were compared against
0.52.0. The only addition is the experimental
`@lexical/html/BlockIdHTMLExtension` subpath. Payload only re-exports
the `@lexical/html` root, so no proxy exports need adding or removing.

## Previous Lexical upgrades

- [#18397](#18397) — 0.50.0 →
0.52.0
- [#18149](#18149) — 0.48.0 →
0.50.0
- [#17554](#17554) — 0.45.0 →
0.48.0

This branch was successfully deployed

2 active deployments
Preview – lexical — 0dd78533 Deployed Oct 19, 2026 by vercel[bot]
Preview – lexical-playground — 0dd78533 Deployed Oct 19, 2026 by vercel[bot]
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.

2 participants