Skip to content

[lexical-link] Bug Fix: read the latest state in LinkNode and AutoLinkNode getters - #9080

Merged
etrepum merged 1 commit into
meta:mainfrom
nithin42:fix-linknode-stale-state
Aug 20, 2026
Merged

etrepum merged 1 commit into
meta:mainfrom
nithin42:fix-linknode-stale-state

Conversation

@nithin42

Copy link
Copy Markdown
Contributor

Description

LinkNode's four public accessors all read through getLatest():

getURL(): string { return this.getLatest().__url; }
getTarget(): null | string { return this.getLatest().__target; }
getRel(): null | string { return this.getLatest().__rel; }
getTitle(): null | string { return this.getLatest().__title; }

but four other readers on the same class read the fields off this directly:

isEmailURI(): boolean { return this.__url.startsWith('mailto:'); }
isWebSiteURI(): boolean { return this.__url.startsWith('https://') || this.__url.startsWith('http://'); }
shouldMergeAdjacentLink(otherLink) {
  return this.getType() === otherLink.getType() &&
    this.__url === otherLink.__url && this.__target === otherLink.__target &&
    this.__rel === otherLink.__rel && this.__title === otherLink.__title;
}

plus AutoLinkNode.getIsUnlinked(), which returns this.__isUnlinked.

setURL() and friends go through getWritable(), which clones the node when it has not already been written to in the current update. A reference obtained in an earlier update therefore keeps pointing at the previous version, and these four readers answer from it while getURL() on the very same object answers from the latest one. So after setURL('mailto:...'), getURL() returns the mailto URL and isEmailURI() returns false.

This is reachable from library code, not just from user code holding a node across updates: handleBadNeighbors and $linkNodeTransform in LexicalAutoLinkExtension.ts call shouldMergeAdjacentLink and getIsUnlinked on nodes they hold while mutating them.

Fix

Route these readers through the existing accessors, so the whole class agrees on which version it is reading:

  • isEmailURI / isWebSiteURI use this.getURL()
  • shouldMergeAdjacentLink compares getURL() / getTarget() / getRel() / getTitle() on both sides
  • AutoLinkNode.getIsUnlinked uses this.getLatest().__isUnlinked, matching how LinkNode's own getters are written

No behaviour changes for a node that has not been cloned, which is why the existing tests did not catch it.

Test plan

Added packages/lexical-link/src/__tests__/unit/LinkNodeStaleState.test.ts. Each case creates the node in one editor.update() and mutates it in a second one, which is what makes getWritable() clone:

  • after setURL('mailto:...'), getURL(), isEmailURI() and isWebSiteURI() must agree
  • after changing one link's URL, shouldMergeAdjacentLink against its neighbour must be false
  • after setIsUnlinked(true), getIsUnlinked() must be true
npx vitest --project unit --no-watch packages/lexical-link

All three fail on main (e.g. expected false to be true for getIsUnlinked) and pass with this change. The lexical-link suite is green (8 files, 172 tests), and lexical-markdown, lexical-html and lexical-clipboard are green too (17 files, 547 tests). prettier and eslint are clean.

…kNode getters

isEmailURI, isWebSiteURI, shouldMergeAdjacentLink and AutoLinkNode.getIsUnlinked read this.__url / __target / __rel / __title / __isUnlinked directly, while getURL, getTarget, getRel and getTitle all go through getLatest(). Once a setter has cloned the node these disagree with each other on the same object.
@vercel

vercel Bot commented Aug 19, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview Aug 19, 2026 5:51pm
lexical-playground Ready Ready Preview Aug 19, 2026 5:51pm

Request Review

@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 19, 2026
@etrepum

etrepum commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator

Please wait until all of your PRs are reviewed before submitting any more.

@etrepum
etrepum added this pull request to the merge queue Aug 20, 2026
Merged via the queue into meta:main with commit 21e768a Aug 20, 2026
71 of 73 checks passed
@etrepum etrepum mentioned this pull request Aug 31, 2026

This branch was successfully deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants