Repository navigation
[lexical-react] Bug Fix: Ignore stale asynchronous auto-embed results - #9331
Merged
Merged
Conversation
## Description
An asynchronous `parseUrl` result can outlive the link it describes. Selecting an embed can currently call `insertNode` after the source link is deleted or its URL changes, and a delayed initial match can show an embed menu for an outdated URL.
Capture the URL before parsing, then re-fetch and validate the link's type, attachment, and URL inside the insertion update before changing the selection or inserting anything. Validate the initial menu result against reconciled editor state, including pending edits. Keep the existing unchanged-link and null-selection behavior.
Add deterministic deferred-promise regression tests for deleted links, changed URLs, delayed menu results, and a URL update queued when parsing resolves.
AI assistance: OpenAI Codex was used to develop the patch and regression tests. The verification results below are from commands actually run.
## Test plan
### Before
On upstream `07ded8cbd301d437d8a894e6844bc18f5e74f91c`, with the new regression tests and no production changes:
```sh
pnpm run test-unit packages/lexical-react/src/__tests__/unit/LexicalAutoEmbedPlugin.test.tsx --maxWorkers=1
```
Actual failing output (excerpt):
```text
❯ |unit| packages/lexical-react/src/__tests__/unit/LexicalAutoEmbedPlugin.test.tsx (15 tests | 4 failed) 437ms
× does not embed a link removed while parsing 29ms
× does not embed a link whose URL changed while parsing 22ms
× does not offer to embed a link whose URL changed while parsing 22ms
× does not offer to embed a link with a pending URL change when parsing resolves 18ms
FAIL |unit| packages/lexical-react/src/__tests__/unit/LexicalAutoEmbedPlugin.test.tsx > LexicalAutoEmbedPlugin > does not embed a link removed while parsing
AssertionError: expected "vi.fn()" to not be called at all, but actually been called 1 times
FAIL |unit| packages/lexical-react/src/__tests__/unit/LexicalAutoEmbedPlugin.test.tsx > LexicalAutoEmbedPlugin > does not embed a link whose URL changed while parsing
AssertionError: expected "vi.fn()" to not be called at all, but actually been called 1 times
FAIL |unit| packages/lexical-react/src/__tests__/unit/LexicalAutoEmbedPlugin.test.tsx > LexicalAutoEmbedPlugin > does not offer to embed a link whose URL changed while parsing
AssertionError: expected <ul …(2)><li>…(1)</li></ul> to be null
FAIL |unit| packages/lexical-react/src/__tests__/unit/LexicalAutoEmbedPlugin.test.tsx > LexicalAutoEmbedPlugin > does not offer to embed a link with a pending URL change when parsing resolves
AssertionError: expected <ul …(2)><li>…(1)</li></ul> to be null
Test Files 1 failed (1)
Tests 4 failed | 11 passed (15)
```
### After
Same focused command:
```text
Test Files 1 passed (1)
Tests 15 passed (15)
Duration 1.74s (environment 36%, tests 24%, import 20%, worker 11%, setup 5%, transform 4%)
```
Affected React and link suites:
```sh
pnpm run test-unit packages/lexical-react packages/lexical-link --maxWorkers=1
```
```text
Test Files 53 passed (53)
Tests 521 passed (521)
Duration 14.91s (tests 38%, import 29%, transform 12%, environment 10%, worker 7%, setup 3%)
```
Full unit suite:
```sh
pnpm run test-unit --maxWorkers=1 --vmMemoryLimit=512MB
```
```text
Test Files 380 passed (380)
Tests 9270 passed | 1 skipped (9271)
Duration 131.05s (tests 46%, import 32%, transform 9%, worker 5%, environment 5%, setup 2%)
```
Repository aggregate checks (exit 0):
```sh
NODE_OPTIONS=--max-old-space-size=2048 pnpm run ci-check --max-parallel 1
```
```text
$ npm-run-all --parallel tsc tsc-test tsc-scripts tsc-extension tsc-website flow prettier lint --max-parallel 1
$ tsc
$ tsc -p ./tsconfig.test.json
$ tsc -p ./tsconfig.scripts.json
$ pnpm --filter @lexical/devtools run compile
$ tsc --noEmit
$ pnpm --filter @lexical/website run tsc
$ tsc -p tsconfig.json
$ node ./scripts/check-flow-types.mjs
Running Flow...
Found 0 errors
$ prettier --list-different .
$ eslint ./
```
`git diff --check` also passed. Tested on Linux with Node v24.19.0 and pnpm v11.19.0. Initial concurrent aggregate/full-unit attempts were killed with exit 137; the complete reruns above passed sequentially with bounded memory. Browser, E2E, integration, build, and the other OS/Node matrices were not run.
Tabisharaza
requested review from
acywatson,
etrepum,
fantactuka,
ivailop7,
potatowagon and
zurfyx
as code owners
October 6, 2026 11:09
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
etrepum
reviewed
Oct 6, 2026
…st paste's menu ## Description Choosing an auto-embed option called `parseUrl` a second time and inserted the embed after that second promise resolved, so the PR needed a stale-link check across that await. The menu check also used the default `editor.read()`, which force-commits pending updates, and every config's `parseUrl` ran even though only the last match was used. An older paste whose `parseUrl` resolved after a newer paste's could also replace the newer paste's menu. The plugin now keeps the `parseUrl` result that opened the menu and inserts it synchronously when the option is chosen, inside an update that checks the link is still attached with the same URL. The menu check reads with `'pending'` instead of force-committing, scans configs from the end and stops at the first match (the last match won before, so the chosen config is unchanged), and ignores results from any paste but the newest. ## Test plan ### Before On 5a84c01 with the updated tests: ```sh ./node_modules/.bin/vitest run --project unit packages/lexical-react/src/__tests__/unit/LexicalAutoEmbedPlugin.test.tsx ``` ```text × embeds an unchanged link without parsing its URL again 251ms × embeds an unchanged link with no selection 31ms × does not let an older paste that resolves late replace the menu 40ms AssertionError: expected "vi.fn()" to be called once, but got 2 times AssertionError: expected "vi.fn()" to be called once, but got 2 times AssertionError: expected "vi.fn()" to be called once with arguments: [ LexicalEditor{ …(36) }, …(1) ] Tests 3 failed | 13 passed (16) ``` ### After ```text Tests 16 passed (16) ``` Reading with `'latest'` instead of `'pending'` fails "does not offer to embed a link with a pending URL change when parsing resolves", and dropping the insert-time URL check fails "does not embed a link whose URL changed in a pending update". Only Chromium/jsdom were exercised. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
… link check
## Description
The insert path looked the link up by key, checked `$isLinkNode`, then called `$isCurrentLink`, which repeated both. `$getCurrentLink(key, url)` now returns the attached `LinkNode` with that URL, or null, so the insert path uses the node it returns.
## Test plan
### After
```sh
./node_modules/.bin/vitest run --project unit packages/lexical-react/src/__tests__/unit/LexicalAutoEmbedPlugin.test.tsx
```
```text
Tests 16 passed (16)
```
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…th $assertNodeType
## Description
The auto-embed tests reached the pasted paragraph with `getFirstChildOrThrow<ParagraphNode>()`, whose type parameter is a deprecated unchecked cast. A `$getParagraph()` helper now narrows the root's first child with `$assertNodeType(..., $isParagraphNode)`, and `$getPastedLink()` uses it, without the redundant non-null assertion.
## Test plan
### After
```sh
./node_modules/.bin/vitest run --project unit packages/lexical-react/src/__tests__/unit/LexicalAutoEmbedPlugin.test.tsx
```
```text
Tests 16 passed (16)
```
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
etrepum
force-pushed
the
fix/stale-auto-embed-results
branch
from
October 6, 2026 15:57
b7b95d6 to
5a84c01
Compare
etrepum
approved these changes
Oct 6, 2026
zurfyx
added a commit
that referenced
this pull request
Oct 15, 2026
## Description The changes merged since v0.52.0 predate changesets, so without entries the v0.53.0 section would leave them out, including the breaking removal of the deprecated import extensions (#9316). This adds a changeset for every user-facing pull request in v0.52.0..main, written from each pull request, with a `PR: #N` line (they land in this pull request rather than the original ones) and the original author's handle: - breaking: #9316, with the full replacement table as `Migration:` - feature: #9312 - fix: #9335, #9332, #9331, #9328, #9325, #9317, #9321, #9320, #9319, #9283, #9303, #9295, #9291, #9260, #9300, #9301, #9272, #9267, #9302, #9261, #9262, #9263, #9258 - perf: #9264 Skipped as not user-facing: dependency bumps (all devDependencies), website and docs updates, test and CI changes, the private devtools extension and eslint-plugin-internal, and #9353 (a behavior-preserving Flow `Object` to `any` change). It also adds a `[chore]` changeset for this pull request itself, which adds CHANGELOG.md to the `lexical` package's `files`. ## Test plan ### Before ``` $ node scripts/changesets/check.mjs --base origin/main --head HEAD --coverage warn # at the previous commit warning: This pull request changes published code without a changeset for: lexical: packages/lexical/package.json (files) ... Changeset check passed: 0 pending changeset(s) valid; coverage: 1 warning(s), reported only. ``` ### After ``` $ node scripts/changesets/check.mjs --base origin/main Changeset check passed: 27 pending changeset(s) valid; coverage: lexical changed, each named by a changeset. ``` The `latest` release step in a throwaway clone of this branch, with the real tags: ``` $ LATEST_RELEASE=v0.52.0 npm_package_version=0.53.0 node scripts/changesets/release.mjs --date 2026-10-30 Added v0.53.0 to CHANGELOG.md from 27 changeset(s). $ ls .changeset changelog.cjs config.json README.md $ sed -n 1,9p CHANGELOG.md ## v0.53.0 (2026-10-30) ### Breaking changes - **@lexical/code-core, @lexical/code-shiki, @lexical/html, @lexical/link, @lexical/list, @lexical/mdast, @lexical/rich-text, @lexical/table**: Remove the extensions deprecated in v0.52.0 and earlier ([#9316](#9316)) The deprecated import and alias extensions are removed. The `*ImportRules` arrays, including `HorizontalRuleImportRules`, stay. $ grep -n '^### ' CHANGELOG.md | head -7 3:### Breaking changes 28:### Features 36:### Fixes 98:### Performance 102:### Other 106:### Contributors 110:### All changes $ sed -n '/^### Contributors/,+2p' CHANGELOG.md ### Contributors @Tabisharaza, @etrepum, @mbret, @maximilliangrand, @Vedthakar, @rinarakaki, @potatowagon, @followdarko, Gerard Rovira $ sed -n '/^### All changes/,/^## v0.52.0/p' CHANGELOG.md | sed -n '5,6p;$p' | head -2 - [lexical-yjs][Chore] Change last `Object` to `any` in lexical ([#9353](#9353)) Sam Zhou - [lexical-eslint-plugin-internal] Chore: lint window messaging channel scoping ([#9339](#9339)) Sherry ``` (`### All changes` has 50 lines: the 48 commits after v0.52.0, without the `v0.52.0 (#9252)` bump commit, plus this branch's two commits.) Running again before that release PR is merged: ``` $ git tag v0.53.0 # tagged, but CHANGELOG.md on main has no v0.53.0 section $ npm_package_version=0.54.0 node scripts/changesets/release.mjs CHANGELOG.md has no v0.53.0 section, so the v0.53.0 release pull request is not merged yet. Merge it (it consumes the changesets for v0.53.0) before cutting v0.54.0; running again now would put the same changesets in both releases. (exit 1) $ npm_package_version=0.53.1 node scripts/changesets/release.mjs Refusing to release 0.53.1 as a patch: 1 pending [breaking] changeset(s) need a minor release: - .changeset/remove-deprecated-import-extensions.md: Remove the extensions deprecated in v0.52.0 and earlier Run the release with the "minor" increment instead. (exit 1) ``` A prerelease publish (lexical at 0.52.1-nightly.20261016.0, nothing built, so the export check that follows fails as expected): ``` $ node scripts/npm/prepare-release.mjs [lexical] CHANGELOG.md lists pending changes as Unreleased [lexical] package.json references files that are not present in packages/lexical: ./dist/Lexical.dev.js $ sed -n 1,5p packages/lexical/CHANGELOG.md ## Unreleased Merged after the latest stable release and included in 0.52.1-nightly.20261016.0. These entries move into a version section when the next stable release is cut. ### Breaking changes $ git status --short CHANGELOG.md (clean: only the gitignored package copy changed) ```
zurfyx
added a commit
that referenced
this pull request
Oct 15, 2026
## Description The changes merged since v0.52.0 predate changesets, so without entries the v0.53.0 section would leave them out, including the breaking removal of the deprecated import extensions (#9316). This adds a changeset for every user-facing pull request in v0.52.0..main, written from each pull request, with a `PR: #N` line (they land in this pull request rather than the original ones) and the original author's handle: - breaking: #9316, with the full replacement table as `Migration:` - feature: #9312 - fix: #9335, #9332, #9331, #9328, #9325, #9317, #9321, #9320, #9319, #9283, #9303, #9295, #9291, #9260, #9300, #9301, #9272, #9267, #9302, #9261, #9262, #9263, #9258 - perf: #9264 Skipped as not user-facing: dependency bumps (all devDependencies), website and docs updates, test and CI changes, the private devtools extension and eslint-plugin-internal, and #9353 (a behavior-preserving Flow `Object` to `any` change). Four fixes change observable output or behavior, so their changesets have a `Verify:` paragraph and are listed under Behavior changes: #9303 (new tabs get no `window.opener`), #9272 (imported code content is normalized), #9261 (`$patchStyleText` styles the selection it is given), #9319 (editor keys and namespaces are a counter without a DOM). It also adds a `[chore]` changeset for this pull request itself, which adds CHANGELOG.md to the `lexical` package's `files`. ## Test plan ### Before ``` $ node scripts/changesets/check.mjs --base origin/main --head HEAD --coverage warn # at the previous commit warning: This pull request changes published code without a changeset for: lexical: packages/lexical/package.json (files) ... Changeset check passed: 0 pending changeset(s) valid; coverage: 1 warning(s), reported only. ``` ### After ``` $ node scripts/changesets/check.mjs --base origin/main Changeset check passed: 27 pending changeset(s) valid; coverage: lexical changed, each named by a changeset. ``` The `latest` release step in a throwaway clone of this branch, with the real tags: ``` $ LATEST_RELEASE=v0.52.0 npm_package_version=0.53.0 node scripts/changesets/release.mjs --date 2026-10-30 Added v0.53.0 to CHANGELOG.md from 27 changeset(s). $ ls .changeset changelog.cjs config.json README.md $ sed -n 1,9p CHANGELOG.md ## v0.53.0 (2026-10-30) ### Breaking changes - **@lexical/code-core, @lexical/code-shiki, @lexical/html, @lexical/link, @lexical/list, @lexical/mdast, @lexical/rich-text, @lexical/table**: Remove the extensions deprecated in v0.52.0 and earlier ([#9316](#9316)) The deprecated import and alias extensions are removed. The `*ImportRules` arrays, including `HorizontalRuleImportRules`, stay. $ grep -n '^### ' CHANGELOG.md | head -8 3:### Breaking changes 28:### Behavior changes 54:### Features 62:### Fixes 108:### Performance 112:### Other 116:### Contributors 120:### All changes $ sed -n '/^### Behavior changes/,+7p' CHANGELOG.md ### Behavior changes - **@lexical/link**: Open new-tab links from `ClickableLinkPlugin` / `registerClickableLink` without `window.opener` ([#9303](#9303)) This prevents the opened page from navigating the editor's tab (reverse tabnabbing). Same-tab opens are unchanged. Verify: pages opened from editor links that relied on `window.opener`. $ node scripts/changesets/range.mjs --from 0.52.0 --breaking --json # (kind, [(pr, behavior)]) [('breaking', [(9316, False)]), ('behavior', [(9303, True), (9272, True), (9261, True), (9319, True)])] $ sed -n '/^### Contributors/,+2p' CHANGELOG.md ### Contributors @Tabisharaza, @etrepum, @mbret, @maximilliangrand, @Vedthakar, @rinarakaki, @potatowagon, @followdarko, Gerard Rovira $ sed -n '/^### All changes/,/^## v0.52.0/p' CHANGELOG.md | sed -n '5,6p;$p' | head -2 - [lexical-yjs][Chore] Change last `Object` to `any` in lexical ([#9353](#9353)) Sam Zhou - [lexical-eslint-plugin-internal] Chore: lint window messaging channel scoping ([#9339](#9339)) Sherry ``` (`### All changes` has 50 lines: the 48 commits after v0.52.0, without the `v0.52.0 (#9252)` bump commit, plus this branch's two commits.) Running again before that release PR is merged: ``` $ git tag v0.53.0 # tagged, but CHANGELOG.md on main has no v0.53.0 section $ npm_package_version=0.54.0 node scripts/changesets/release.mjs CHANGELOG.md has no v0.53.0 section, so the v0.53.0 release pull request is not merged yet. Merge it (it consumes the changesets for v0.53.0) before cutting v0.54.0; running again now would put the same changesets in both releases. (exit 1) $ npm_package_version=0.53.1 node scripts/changesets/release.mjs Refusing to release 0.53.1 as a patch: 1 pending [breaking] changeset(s) need a minor release: - .changeset/remove-deprecated-import-extensions.md: Remove the extensions deprecated in v0.52.0 and earlier Run the release with the "minor" increment instead. (exit 1) ``` A prerelease publish (lexical at 0.52.1-nightly.20261016.0, nothing built, so the export check that follows fails as expected): ``` $ node scripts/npm/prepare-release.mjs [lexical] CHANGELOG.md lists pending changes as Unreleased [lexical] package.json references files that are not present in packages/lexical: ./dist/Lexical.dev.js $ sed -n 1,5p packages/lexical/CHANGELOG.md ## Unreleased Merged after the latest stable release and included in 0.52.1-nightly.20261016.0. These entries move into a version section when the next stable release is cut. ### Breaking changes $ git status --short CHANGELOG.md (clean: only the gitignored package copy changed) ```
zurfyx
added a commit
that referenced
this pull request
Oct 15, 2026
## Description The changes merged since v0.52.0 predate changesets, so without entries the v0.53.0 section would leave them out, including the breaking removal of the deprecated import extensions (#9316). This adds a changeset for every user-facing pull request in v0.52.0..main, written from each pull request, with a `PR: #N` line (they land in this pull request rather than the original ones) and the original author's handle: - breaking: #9316, with the full replacement table as `Migration:` - feature: #9312 - fix: #9335, #9332, #9331, #9328, #9325, #9317, #9321, #9320, #9319, #9283, #9303, #9295, #9291, #9260, #9300, #9301, #9272, #9267, #9302, #9261, #9262, #9263, #9258 - perf: #9264 Skipped as not user-facing: dependency bumps (all devDependencies), website and docs updates, test and CI changes, the private devtools extension and eslint-plugin-internal, and #9353 (a behavior-preserving Flow `Object` to `any` change). Four fixes change observable output or behavior, so their changesets have a `Verify:` paragraph and are listed under Behavior changes: #9303 (new tabs get no `window.opener`), #9272 (imported code content is normalized), #9261 (`$patchStyleText` styles the selection it is given), #9319 (editor keys and namespaces are a counter without a DOM). It also adds a `[chore]` changeset for this pull request itself, which adds CHANGELOG.md to the `lexical` package's `files`. ## Test plan ### Before ``` $ node scripts/changesets/check.mjs --base origin/main --head HEAD --coverage warn # at the previous commit warning: This pull request changes published code without a changeset for: lexical: packages/lexical/package.json (files) ... Changeset check passed: 0 pending changeset(s) valid; coverage: 1 warning(s), reported only. ``` ### After ``` $ node scripts/changesets/check.mjs --base origin/main Changeset check passed: 27 pending changeset(s) valid; coverage: lexical changed, each named by a changeset. ``` The `latest` release step in a throwaway clone of this branch, with the real tags: ``` $ LATEST_RELEASE=v0.52.0 npm_package_version=0.53.0 node scripts/changesets/release.mjs --date 2026-10-30 Added v0.53.0 to CHANGELOG.md from 27 changeset(s). $ ls .changeset changelog.cjs config.json README.md $ sed -n 1,9p CHANGELOG.md ## v0.53.0 (2026-10-30) ### Breaking changes - **@lexical/code-core, @lexical/code-shiki, @lexical/html, @lexical/link, @lexical/list, @lexical/mdast, @lexical/rich-text, @lexical/table**: Remove the extensions deprecated in v0.52.0 and earlier ([#9316](#9316)) The deprecated import and alias extensions are removed. The `*ImportRules` arrays, including `HorizontalRuleImportRules`, stay. $ grep -n '^### ' CHANGELOG.md | head -8 3:### Breaking changes 28:### Behavior changes 54:### Features 62:### Fixes 108:### Performance 112:### Other 116:### Contributors 120:### All changes $ sed -n '/^### Behavior changes/,+7p' CHANGELOG.md ### Behavior changes - **@lexical/link**: Open new-tab links from `ClickableLinkPlugin` / `registerClickableLink` without `window.opener` ([#9303](#9303)) This prevents the opened page from navigating the editor's tab (reverse tabnabbing). Same-tab opens are unchanged. Verify: pages opened from editor links that relied on `window.opener`. $ node scripts/changesets/range.mjs --from 0.52.0 --breaking --json # (kind, [(pr, behavior)]) [('breaking', [(9316, False)]), ('behavior', [(9303, True), (9272, True), (9261, True), (9319, True)])] $ sed -n '/^### Contributors/,+2p' CHANGELOG.md ### Contributors @Tabisharaza, @etrepum, @mbret, @maximilliangrand, @Vedthakar, @rinarakaki, @potatowagon, @followdarko, Gerard Rovira $ sed -n '/^### All changes/,/^## v0.52.0/p' CHANGELOG.md | sed -n '5,6p;$p' | head -2 - [lexical-yjs][Chore] Change last `Object` to `any` in lexical ([#9353](#9353)) Sam Zhou - [lexical-eslint-plugin-internal] Chore: lint window messaging channel scoping ([#9339](#9339)) Sherry ``` (`### All changes` has 50 lines: the 48 commits after v0.52.0, without the `v0.52.0 (#9252)` bump commit, plus this branch's two commits.) Running again before that release PR is merged: ``` $ git tag v0.53.0 # tagged, but CHANGELOG.md on main has no v0.53.0 section $ npm_package_version=0.54.0 node scripts/changesets/release.mjs CHANGELOG.md has no v0.53.0 section, so the v0.53.0 release pull request is not merged yet. Merge it (it consumes the changesets for v0.53.0) before cutting v0.54.0; running again now would put the same changesets in both releases. (exit 1) $ npm_package_version=0.53.1 node scripts/changesets/release.mjs Refusing to release 0.53.1 as a patch: 1 pending [breaking] changeset(s) need a minor release: - .changeset/remove-deprecated-import-extensions.md: Remove the extensions deprecated in v0.52.0 and earlier Run the release with the "minor" increment instead. (exit 1) ``` A prerelease publish (lexical at 0.52.1-nightly.20261016.0, nothing built, so the export check that follows fails as expected): ``` $ node scripts/npm/prepare-release.mjs [lexical] CHANGELOG.md lists pending changes as Unreleased [lexical] package.json references files that are not present in packages/lexical: ./dist/Lexical.dev.js $ sed -n 1,5p packages/lexical/CHANGELOG.md ## Unreleased Merged after the latest stable release and included in 0.52.1-nightly.20261016.0. These entries move into a version section when the next stable release is cut. ### Breaking changes $ git status --short CHANGELOG.md (clean: only the gitignored package copy changed) ```
Merged
This branch was successfully deployed
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
An asynchronous
parseUrlresult can outlive the link it describes. Selecting an embed can currently callinsertNodeafter the source link is deleted or its URL changes, and a delayed initial match can show an embed menu for an outdated URL.Capture the URL before parsing, then re-fetch and validate the link's type, attachment, and URL inside the insertion update before changing the selection or inserting anything. Validate the initial menu result against reconciled editor state, including pending edits. Keep the existing unchanged-link and null-selection behavior.
Add deterministic deferred-promise regression tests for deleted links, changed URLs, delayed menu results, and a URL update queued when parsing resolves.
AI assistance: OpenAI Codex was used to develop the patch and regression tests. The verification results below are from commands actually run.
Test plan
Before
On upstream
07ded8cbd301d437d8a894e6844bc18f5e74f91c, with the new regression tests and no production changes:Actual failing output (excerpt):
After
Same focused command:
Affected React and link suites:
Full unit suite:
Repository aggregate checks (exit 0):
git diff --checkalso passed. Tested on Linux with Node v24.19.0 and pnpm v11.19.0. Initial concurrent aggregate/full-unit attempts were killed with exit 137; the complete reruns above passed sequentially with bounded memory. Browser, E2E, integration, build, and the other OS/Node matrices were not run.Description
Describe the changes in this pull request
Closes #
Test plan
Before
Insert relevant screenshots/recordings/automated-tests
After
Insert relevant screenshots/recordings/automated-tests