Repository navigation
[lexical-link] Bug Fix: read the latest state in LinkNode and AutoLinkNode getters - #9080
Merged
Merged
Conversation
…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.
nithin42
requested review from
acywatson,
etrepum,
fantactuka,
ivailop7,
potatowagon and
zurfyx
as code owners
August 19, 2026 17:49
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Collaborator
|
Please wait until all of your PRs are reviewed before submitting any more. |
etrepum
approved these changes
Aug 19, 2026
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
LinkNode's four public accessors all read throughgetLatest():but four other readers on the same class read the fields off
thisdirectly:plus
AutoLinkNode.getIsUnlinked(), which returnsthis.__isUnlinked.setURL()and friends go throughgetWritable(), 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 whilegetURL()on the very same object answers from the latest one. So aftersetURL('mailto:...'),getURL()returns the mailto URL andisEmailURI()returnsfalse.This is reachable from library code, not just from user code holding a node across updates:
handleBadNeighborsand$linkNodeTransforminLexicalAutoLinkExtension.tscallshouldMergeAdjacentLinkandgetIsUnlinkedon 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/isWebSiteURIusethis.getURL()shouldMergeAdjacentLinkcomparesgetURL()/getTarget()/getRel()/getTitle()on both sidesAutoLinkNode.getIsUnlinkedusesthis.getLatest().__isUnlinked, matching howLinkNode's own getters are writtenNo 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 oneeditor.update()and mutates it in a second one, which is what makesgetWritable()clone:setURL('mailto:...'),getURL(),isEmailURI()andisWebSiteURI()must agreeshouldMergeAdjacentLinkagainst its neighbour must befalsesetIsUnlinked(true),getIsUnlinked()must betrueAll three fail on
main(e.g.expected false to be trueforgetIsUnlinked) and pass with this change. Thelexical-linksuite is green (8 files, 172 tests), andlexical-markdown,lexical-htmlandlexical-clipboardare green too (17 files, 547 tests).prettierandeslintare clean.