Skip to content

[Breaking Change][lexical][*] Chore: deprecate unsafe type parameters on node traversal methods - #8661

Merged
etrepum merged 7 commits into
meta:mainfrom
etrepum:claude/confident-wright-uhbb3b
Jun 9, 2026
Merged

etrepum merged 7 commits into
meta:mainfrom
etrepum:claude/confident-wright-uhbb3b

Conversation

@etrepum

@etrepum etrepum commented Jun 9, 2026 •

Copy link
Copy Markdown
Collaborator

Breaking Change

This is a types-only change to the API but some unsafe inference will require changes to the call sites to pass the type check. For example, this unsafe code would pass type checks before but fail after this PR:

const node: ParagraphNode | null = $getRoot().getFirstChild();

A direct port of this unsafe code would use a cast (no safety or correctness difference):

const node = $getRoot().getFirstChild() as ParagraphNode | null;

To write safe code, you must use a guard for runtime narrowing. For example:

const node = $getRoot().getFirstChild();
if ($isParagraphNode(node)) {
  // node is narrowed to ParagraphNode in this branch
}

Existing code that explicitly uses a type argument to do an unsafe cast will still work, but that usage is deprecated and will be removed in some future version of lexical (e.g. $getRoot().getFirstChild<ParagraphNode>() is now deprecated).

Description

The zero-argument generics on the LexicalNode and ElementNode traversal methods (getParent(OrThrow), getPreviousSibling(s), getNextSibling(s), getChildren, getFirstChild(OrThrow), getLastChild(OrThrow), getChildAtIndex, getFirstDescendant, getLastDescendant, and getDescendantByIndex) were implicit unchecked casts: there is no inference site, so the only sound type argument is the constraint itself and any other instantiation is equivalent to an unchecked cast.

Each method is now declared as an overload pair: a documented non-generic signature that returns the base type (LexicalNode or ElementNode | null as appropriate), plus the old generic signature marked @deprecated so existing call sites keep compiling but get flagged in editors and in the generated API documentation. The deprecated overloads can be removed in a future release.

The type parameter is no longer inferred from the contextual (assignment) type, so call sites that relied on that implicit cast now fail to compile and must narrow with a type guard or use an explicit cast; all such call sites in the repo have been migrated, with no intended runtime behavior changes.

Test plan

  • Manually verify that the deprecations show up in QA with the VSCode language server, and that the deprecations don't show up for call sites without the explicit generic. This PR doesn't fix all use sites.

…l methods

The zero-argument generics on the LexicalNode and ElementNode traversal
methods (getParent(OrThrow), getPreviousSibling(s), getNextSibling(s),
getChildren, getFirstChild(OrThrow), getLastChild(OrThrow),
getChildAtIndex, getFirstDescendant, getLastDescendant, and
getDescendantByIndex) were implicit unchecked casts: there is no
inference site, so the only sound type argument is the constraint
itself and any other instantiation is equivalent to an unchecked cast.

Each method is now declared as an overload pair: a documented
non-generic signature that returns the base type (LexicalNode or
ElementNode | null as appropriate), plus the old generic signature
marked @deprecated so existing call sites keep compiling but get
flagged in editors and in the generated API documentation. The
deprecated overloads can be removed in a future release.

The type parameter is no longer inferred from the contextual
(assignment) type, so call sites that relied on that implicit cast now
fail to compile and must narrow with a type guard or use an explicit
cast; all such call sites in the repo have been migrated, with no
intended runtime behavior changes.

https://claude.ai/code/session_013BorfSoh3hq2JeW1vWvDKU
@vercel

vercel Bot commented Jun 9, 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, Comment Jun 9, 2026 7:42pm
lexical-playground Ready Ready Preview, Comment Jun 9, 2026 7:42pm

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 Jun 9, 2026
… and $getNodeByKeyOrThrow

Applies the same overload-pair deprecation used for the node traversal
methods: a documented non-generic signature returning
LexicalNode (| null) plus the old generic signature marked @deprecated,
since the type parameter has no inference site and is an implicit
unchecked cast.

Call sites in shipped source that passed an explicit type argument or
relied on contextual inference have been migrated to type guards where
one already followed, or explicit casts where the type is guaranteed by
construction (table observer/selection keys, getLatest, getParent),
with no intended runtime behavior changes.

https://claude.ai/code/session_013BorfSoh3hq2JeW1vWvDKU
claude added 2 commits June 9, 2026 19:02
…he Flow types

Applies the same overload-pair deprecation to the Flow declarations for
the LexicalNode and ElementNode traversal methods, $getNodeByKey, and
$getNodeByKeyOrThrow: a non-generic primary signature returning the
base node type, with the old generic signature retained behind a
@deprecated docblock.

This also fixes some drift from the TypeScript types: getParents is
non-generic in TypeScript, $getNodeByKey was missing the optional
_editorState parameter, and plain calls contextually typed with a
nullable hint (e.g. `const a: LexicalNode | null = x.getFirstChild()`)
did not previously typecheck under Flow at all because Flow refused to
infer the type parameter from a union hint; they now resolve to the
non-generic overload. Calls with an explicit type argument still
resolve to the deprecated generic overload, and implicit contextual
casts to a subtype are now errors, matching the TypeScript behavior.

https://claude.ai/code/session_013BorfSoh3hq2JeW1vWvDKU
…nt annotations and fix traversal docs

Removes local variable type annotations that are now exactly identical
to what the non-generic traversal signatures infer. Annotations that
look redundant but break a circular inference through a loop back-edge
(TS7022) are kept and commented as such.

Also rewrites the sibling traversal docblocks for grammar: the singular
getPreviousSibling/getNextSibling described "siblings", and the plural
variants had "it's" for "its".

https://claude.ai/code/session_013BorfSoh3hq2JeW1vWvDKU
…#8661 in the TS7022 annotation comments

These annotations are only necessary because overload selection (and
previously, generic inference) requires the receiver's narrowed type,
which is circular through the loop back-edge. Once the deprecated
generic signatures from meta#8661 are removed, the plain non-generic
signatures no longer trigger the circularity, so these annotations can
be removed in the same cleanup.

https://claude.ai/code/session_013BorfSoh3hq2JeW1vWvDKU
…safe casts at migrated call sites with type guards

The call sites migrated away from the deprecated generic signatures
should not re-introduce the same unsafety as unchecked casts:

- TableNode.getColumnCount, TableObserver cell getters, and
  $getTableCellNodeRect now narrow with $isTableRowNode /
  $isTableCellNode instead of casting
- LexicalTableSelectionHelpers uses a $getTableNodeByKeyOrThrow helper
  (guard + invariant, following $getTableAndElementByKey) for table
  keys instead of casting
- $handleIndent relies on the isNestedListNode type guard, removing a
  stale comment that predated isNestedListNode being a guard
- $wrapNodesImpl walks with an honestly-typed LexicalNode target
  instead of casting the previous sibling to ElementNode
- test files use vitest assert() with node type guards instead of
  casts, including a pre-existing cast in LinkExtension.test.ts

The remaining casts in LexicalNode.getParent/getLatest are the typed
boundary over the NodeKey-keyed nodeMap storage (previously hidden
inside $getNodeByKey's implementation) and are commented with their
invariants.

https://claude.ai/code/session_013BorfSoh3hq2JeW1vWvDKU
@etrepum
etrepum marked this pull request as ready for review June 9, 2026 20:37
@etrepum etrepum changed the title [lexical][*] Chore: deprecate unsafe type parameters on node traversal methods [Breaking Change][lexical][*] Chore: deprecate unsafe type parameters on node traversal methods Jun 9, 2026
@etrepum
etrepum added this pull request to the merge queue Jun 9, 2026
Merged via the queue into meta:main with commit 9359140 Jun 9, 2026
44 checks passed
@etrepum
etrepum deleted the claude/confident-wright-uhbb3b branch June 9, 2026 22:31
etrepum pushed a commit to etrepum/lexical that referenced this pull request Jun 10, 2026
…eta#8661 follow-up)

Migrate the remaining call sites (all in tests) off the deprecated unsafe
type parameters that meta#8661 added to the node traversal methods
(getFirstChild<T>(), getParent<T>(), getChildAtIndex<T>(), $getNodeByKey<T>(),
etc.). The deprecated overloads themselves are retained for backwards
compatibility with consumers.

Add a $assertNodeType test helper that narrows a node via a type guard
instead of an unchecked cast, and use it (alongside the existing $is*
guards) in place of the deprecated type parameters and a few remaining
unsafe `as` casts in the affected tests.
etrepum pushed a commit to etrepum/lexical that referenced this pull request Jun 11, 2026
…][lexical-react][lexical-extension][lexical-devtools-core][lexical-playground] Bug Fix: Named-slots audit fixes: collab first-set sync, in-slot copy/cut, export gating, slot cycle guard (meta#8603)

Fixes every issue from the named-slots audit of this PR, in one
cherry-pickable commit.

Critical:
- yjs V1: route a changed `slots` key in YTextEvent/YXmlEvent to
  syncSlotsFromYjs. The first $setSlot on a synced host (and its undo)
  integrates the slots Y.Map in the same transaction as its content, so
  no YMapEvent fires and the slot never reached peers; the follow-up
  peer edit then crashed on an undefined collab node or deleted the
  originator's slot from the shared doc.
- yjs V2: make $equalYTypePNode slots-aware (and exclude the `slots`
  attribute from the plain attribute comparison) so the dirty scan
  recurses instead of repointing the mapping — the originator's first
  $setSlot is now actually written to yjs.
- clipboard/html: walk the RangeSelection's slot frame (new core
  $getSlotFrame) in $generateJSONFromSelectedNodes and
  $generateDOMFromNodes. A selection wholly inside a slot never contains
  its host, so both exporters returned empty payloads and cut inside a
  slot was silent data loss.
- clipboard/html: gate the includeChildrenWhenSelected child promotion
  on NodeSelection. A partial RangeSelection over a host exported the
  full unsliced child text plus wholly unselected siblings on both
  channels.

Major:
- selection: insertNodes with the caret on an empty slot value seeds a
  paragraph and redirects instead of throwing "to have a block
  ancestor" (reachable via Ctrl+A in an empty slot, then paste).
- core: reverse cycle guard $errorOnSlotCycleChild in ElementNode.splice
  and insertBefore/insertAfter/replace. Closing a cycle through the
  children channel (slotValue.append(host)) previously hung the commit
  inside isAttached's up-walk.
- yjs V1: sync root-host slots (the root branch never called
  syncSlotsFromLexical, so $setSlot($getRoot(), ...) silently never
  synced).
- yjs V1/V2: validate-and-skip hostile or invalid remote slot entries
  (reserved names, non-shared-type values, missing __type, invalid slot
  value shapes, duplicate shared types under two names) instead of
  throwing inside the observer update; aliased entries are first-name-
  wins.
- yjs: reserve the `slots` attribute key in property sync in both
  directions for both versions; restored V1 hosts no longer carry a junk
  `slots` Y.Map property, and a user property named `slots` can no
  longer clobber the channel.
- yjs V1: sweep the transaction's deleted structs after remote events
  (mirroring V2) so a remote host deletion no longer leaks its slot
  values' collabNodeMap entries.
- playground: drop CardExtension's ClickAfterLastBlockExtension
  override. The last-wins config merge silently clobbered the app's
  $isCodeNode predicate, and CardNode.isShadowRoot() already satisfies
  $defaultShouldInsertAfter.

Minor:
- clipboard: the excluded-slot-value guard also verifies the exported
  node type, catching the 1-child excludeFromCopy case that silently
  exported the child as the slot value; declare `slots` on
  BaseSerializedNode.
- html: $appendNodeToHTML resolves the session DOM render config so
  disabledForSession overrides apply inside slot subtrees.
- core: $setSlot re-setting the same node under the same name is a
  no-op instead of tripping the already-slotted invariant.
- utils: $dfsWithSlots/$reverseDfsWithSlots stop before the endNode's
  slot subtrees (inclusive stop), document the in-slot endNode
  limitation, and carry @experimental tags.
- react: useLexicalSlot detaches the previously appended container on
  nodeKey/slotName change; useCharacterLimit advances the wrap budget
  past slotted decorator leaves so the overflow boundary lands exactly.
- extension: NodeSelectionDataSelectedExtension mirrors a NodeSelection
  already committed at registration, clears data-selected attributes on
  teardown, and raises an invariant for configured-but-unregistered
  classes.
- yjs V2: keep the (empty) slots Y.Map on remove-last to narrow the
  concurrent-creation window; slot membership reads are snapshot-aware
  (typeMapGetAllSnapshot) so historical renders show historical slots;
  guard the remaining _collabNode dereferences.
- devtools-core: recurse into DecoratorNode children so a decorator
  host's slots are visible when reached through the children channel.
- playground: import rules no longer fabricate seeded "Title" content
  or drop a PullQuote's non-slot children (they land in the quote
  slot); any orphan slot wrapper closes the open rewrap run; chrome
  handlers are gated on editor.isEditable(); nested hosts' chrome is
  clickable (slot-wrapper bail only applies to the host's own slots);
  Tab from the title seeds an empty body paragraph when none exists;
  e2e slash-menu helpers use waitForSelector instead of sleep(300);
  CardSlotFix.spec.mjs renamed to CardSlot.spec.mjs; stale comments
  corrected.

API modernization (new code must use the current protocols):
- All node classes introduced by this commit's tests use the $config()
  protocol instead of legacy static getType/clone/importJSON
  (CardLikeNode, PlainShadowRootNode, ExcludedShadowRootNode,
  TestUpdateDOMTrueHostNode — the latter carrying its instance state via
  afterCloneFrom). The PR's other new classes (CardNode, PullQuoteNode,
  SlotContainerNode and the newer test nodes) already used $config().
- $getSlot drops its unchecked type parameter (the pattern deprecated by
  meta#8661) — as a brand-new @experimental API it returns LexicalNode | null
  and callers narrow with type guards; flow declaration updated and the
  explicit generic call sites converted.
- New test code in this commit avoids the deprecated traversal type
  parameters.

Tests: 23 new regression tests across lexical, lexical-clipboard,
lexical-yjs (including real two-doc relay observer tests for first-set,
undo, hostile data, root slots, and the deletion-leak sweep),
lexical-utils, lexical-react, lexical-extension, lexical-devtools-core,
and the playground. Full unit suite: 169 files, 3965 passed. tsc, flow,
prettier, and eslint clean.

Intentionally not addressed here (need product/design decisions rather
than fixes): the SELECT_ALL shadow-root scoping behavior change (kept,
already e2e-pinned; recommend a separate PR + breaking-change note),
per-client slot Map ordering under concurrent distinct-name adds
(inherent to the Y.Map channel design), and a mixed-version rollout
note for pre-slots V1 clients.

https://claude.ai/code/session_0125UE7Cv1mUaM82UH8N1nJX
etrepum pushed a commit to etrepum/lexical that referenced this pull request Jun 11, 2026
…][lexical-react][lexical-extension][lexical-devtools-core][lexical-playground] Bug Fix: Named-slots audit fixes: collab first-set sync, in-slot copy/cut, export gating, slot cycle guard (meta#8603)

Fixes every issue from the named-slots audit of this PR, in one
cherry-pickable commit.

Critical:
- yjs V1: route a changed `slots` key in YTextEvent/YXmlEvent to
  syncSlotsFromYjs. The first $setSlot on a synced host (and its undo)
  integrates the slots Y.Map in the same transaction as its content, so
  no YMapEvent fires and the slot never reached peers; the follow-up
  peer edit then crashed on an undefined collab node or deleted the
  originator's slot from the shared doc.
- yjs V2: make $equalYTypePNode slots-aware (and exclude the `slots`
  attribute from the plain attribute comparison) so the dirty scan
  recurses instead of repointing the mapping — the originator's first
  $setSlot is now actually written to yjs.
- clipboard/html: walk the RangeSelection's slot frame (new core
  $getSlotFrame) in $generateJSONFromSelectedNodes and
  $generateDOMFromNodes. A selection wholly inside a slot never contains
  its host, so both exporters returned empty payloads and cut inside a
  slot was silent data loss.
- clipboard/html: gate the includeChildrenWhenSelected child promotion
  on NodeSelection. A partial RangeSelection over a host exported the
  full unsliced child text plus wholly unselected siblings on both
  channels.

Major:
- selection: insertNodes with the caret on an empty slot value seeds a
  paragraph and redirects instead of throwing "to have a block
  ancestor" (reachable via Ctrl+A in an empty slot, then paste).
- core: reverse cycle guard $errorOnSlotCycleChild in ElementNode.splice
  and insertBefore/insertAfter/replace. Closing a cycle through the
  children channel (slotValue.append(host)) previously hung the commit
  inside isAttached's up-walk.
- yjs V1: sync root-host slots (the root branch never called
  syncSlotsFromLexical, so $setSlot($getRoot(), ...) silently never
  synced).
- yjs V1/V2: validate-and-skip hostile or invalid remote slot entries
  (reserved names, non-shared-type values, missing __type, invalid slot
  value shapes, duplicate shared types under two names) instead of
  throwing inside the observer update; aliased entries are first-name-
  wins.
- yjs: reserve the `slots` attribute key in property sync in both
  directions for both versions; restored V1 hosts no longer carry a junk
  `slots` Y.Map property, and a user property named `slots` can no
  longer clobber the channel.
- yjs V1: sweep the transaction's deleted structs after remote events
  (mirroring V2) so a remote host deletion no longer leaks its slot
  values' collabNodeMap entries.
- playground: drop CardExtension's ClickAfterLastBlockExtension
  override. The last-wins config merge silently clobbered the app's
  $isCodeNode predicate, and CardNode.isShadowRoot() already satisfies
  $defaultShouldInsertAfter.

Minor:
- clipboard: the excluded-slot-value guard also verifies the exported
  node type, catching the 1-child excludeFromCopy case that silently
  exported the child as the slot value; declare `slots` on
  BaseSerializedNode.
- html: $appendNodeToHTML resolves the session DOM render config so
  disabledForSession overrides apply inside slot subtrees.
- core: $setSlot re-setting the same node under the same name is a
  no-op instead of tripping the already-slotted invariant.
- utils: $dfsWithSlots/$reverseDfsWithSlots stop before the endNode's
  slot subtrees (inclusive stop), document the in-slot endNode
  limitation, and carry @experimental tags.
- react: useLexicalSlot detaches the previously appended container on
  nodeKey/slotName change; useCharacterLimit advances the wrap budget
  past slotted decorator leaves so the overflow boundary lands exactly.
- extension: NodeSelectionDataSelectedExtension mirrors a NodeSelection
  already committed at registration, clears data-selected attributes on
  teardown, and raises an invariant for configured-but-unregistered
  classes.
- yjs V2: keep the (empty) slots Y.Map on remove-last to narrow the
  concurrent-creation window; slot membership reads are snapshot-aware
  (typeMapGetAllSnapshot) so historical renders show historical slots;
  guard the remaining _collabNode dereferences.
- devtools-core: recurse into DecoratorNode children so a decorator
  host's slots are visible when reached through the children channel.
- playground: import rules no longer fabricate seeded "Title" content
  or drop a PullQuote's non-slot children (they land in the quote
  slot); any orphan slot wrapper closes the open rewrap run; chrome
  handlers are gated on editor.isEditable(); nested hosts' chrome is
  clickable (slot-wrapper bail only applies to the host's own slots);
  Tab from the title seeds an empty body paragraph when none exists;
  e2e slash-menu helpers use waitForSelector instead of sleep(300);
  CardSlotFix.spec.mjs renamed to CardSlot.spec.mjs; stale comments
  corrected.

API modernization (new code must use the current protocols):
- All node classes introduced by this commit's tests use the $config()
  protocol instead of legacy static getType/clone/importJSON
  (CardLikeNode, PlainShadowRootNode, ExcludedShadowRootNode,
  TestUpdateDOMTrueHostNode — the latter carrying its instance state via
  afterCloneFrom). The PR's other new classes (CardNode, PullQuoteNode,
  SlotContainerNode and the newer test nodes) already used $config().
- $getSlot drops its unchecked type parameter (the pattern deprecated by
  meta#8661) — as a brand-new @experimental API it returns LexicalNode | null
  and callers narrow with type guards; flow declaration updated and the
  explicit generic call sites converted.
- Every deprecated traversal type parameter in the PR's added code is
  scrubbed (62 call sites across LexicalSlot / LexicalSlotSelection /
  LexicalSlotDfs / SlotClipboardExport tests), using the same
  $assertNodeType(node, $isX) narrowing pattern meta#8667 applied to the
  rest of the test suite; $isTestShadowRootNode /
  $isTestUpdateDOMTrueHostNode guards added to the shared test utils.

Tests: 23 new regression tests across lexical, lexical-clipboard,
lexical-yjs (including real two-doc relay observer tests for first-set,
undo, hostile data, root slots, and the deletion-leak sweep),
lexical-utils, lexical-react, lexical-extension, lexical-devtools-core,
and the playground. Full unit suite: 169 files, 3965 passed. tsc, flow,
prettier, and eslint clean.

Intentionally not addressed here (need product/design decisions rather
than fixes): the SELECT_ALL shadow-root scoping behavior change (kept,
already e2e-pinned; recommend a separate PR + breaking-change note),
per-client slot Map ordering under concurrent distinct-name adds
(inherent to the Y.Map channel design), and a mixed-version rollout
note for pre-slots V1 clients.

https://claude.ai/code/session_0125UE7Cv1mUaM82UH8N1nJX
etrepum pushed a commit to etrepum/lexical that referenced this pull request Jun 12, 2026
…][lexical-react][lexical-extension][lexical-devtools-core][lexical-playground] Bug Fix: Named-slots audit fixes: collab first-set sync, in-slot copy/cut, export gating, slot cycle guard (meta#8603)

Fixes every issue from the named-slots audit of this PR, in one
cherry-pickable commit.

Critical:
- yjs V1: route a changed `slots` key in YTextEvent/YXmlEvent to
  syncSlotsFromYjs. The first $setSlot on a synced host (and its undo)
  integrates the slots Y.Map in the same transaction as its content, so
  no YMapEvent fires and the slot never reached peers; the follow-up
  peer edit then crashed on an undefined collab node or deleted the
  originator's slot from the shared doc.
- yjs V2: make $equalYTypePNode slots-aware (and exclude the `slots`
  attribute from the plain attribute comparison) so the dirty scan
  recurses instead of repointing the mapping — the originator's first
  $setSlot is now actually written to yjs.
- clipboard/html: walk the RangeSelection's slot frame (new core
  $getSlotFrame) in $generateJSONFromSelectedNodes and
  $generateDOMFromNodes. A selection wholly inside a slot never contains
  its host, so both exporters returned empty payloads and cut inside a
  slot was silent data loss.
- clipboard/html: gate the includeChildrenWhenSelected child promotion
  on NodeSelection. A partial RangeSelection over a host exported the
  full unsliced child text plus wholly unselected siblings on both
  channels.

Major:
- selection: insertNodes with the caret on an empty slot value seeds a
  paragraph and redirects instead of throwing "to have a block
  ancestor" (reachable via Ctrl+A in an empty slot, then paste).
- core: reverse cycle guard $errorOnSlotCycleChild in ElementNode.splice
  and insertBefore/insertAfter/replace. Closing a cycle through the
  children channel (slotValue.append(host)) previously hung the commit
  inside isAttached's up-walk.
- yjs V1: sync root-host slots (the root branch never called
  syncSlotsFromLexical, so $setSlot($getRoot(), ...) silently never
  synced).
- yjs V1/V2: validate-and-skip hostile or invalid remote slot entries
  (reserved names, non-shared-type values, missing __type, invalid slot
  value shapes, duplicate shared types under two names) instead of
  throwing inside the observer update; aliased entries are first-name-
  wins.
- yjs: reserve the `slots` attribute key in property sync in both
  directions for both versions; restored V1 hosts no longer carry a junk
  `slots` Y.Map property, and a user property named `slots` can no
  longer clobber the channel.
- yjs V1: sweep the transaction's deleted structs after remote events
  (mirroring V2) so a remote host deletion no longer leaks its slot
  values' collabNodeMap entries.
- playground: drop CardExtension's ClickAfterLastBlockExtension
  override. The last-wins config merge silently clobbered the app's
  $isCodeNode predicate, and CardNode.isShadowRoot() already satisfies
  $defaultShouldInsertAfter.

Minor:
- clipboard: the excluded-slot-value guard also verifies the exported
  node type, catching the 1-child excludeFromCopy case that silently
  exported the child as the slot value; declare `slots` on
  BaseSerializedNode.
- html: $appendNodeToHTML resolves the session DOM render config so
  disabledForSession overrides apply inside slot subtrees.
- core: $setSlot re-setting the same node under the same name is a
  no-op instead of tripping the already-slotted invariant.
- utils: $dfsWithSlots/$reverseDfsWithSlots stop before the endNode's
  slot subtrees (inclusive stop), document the in-slot endNode
  limitation, and carry @experimental tags.
- react: useLexicalSlot detaches the previously appended container on
  nodeKey/slotName change; useCharacterLimit advances the wrap budget
  past slotted decorator leaves so the overflow boundary lands exactly.
- extension: NodeSelectionDataSelectedExtension mirrors a NodeSelection
  already committed at registration, clears data-selected attributes on
  teardown, and raises an invariant for configured-but-unregistered
  classes.
- yjs V2: keep the (empty) slots Y.Map on remove-last to narrow the
  concurrent-creation window; slot membership reads are snapshot-aware
  (typeMapGetAllSnapshot) so historical renders show historical slots;
  guard the remaining _collabNode dereferences.
- devtools-core: recurse into DecoratorNode children so a decorator
  host's slots are visible when reached through the children channel.
- playground: import rules no longer fabricate seeded "Title" content
  or drop a PullQuote's non-slot children (they land in the quote
  slot); any orphan slot wrapper closes the open rewrap run; chrome
  handlers are gated on editor.isEditable(); nested hosts' chrome is
  clickable (slot-wrapper bail only applies to the host's own slots);
  Tab from the title seeds an empty body paragraph when none exists;
  e2e slash-menu helpers use waitForSelector instead of sleep(300);
  CardSlotFix.spec.mjs renamed to CardSlot.spec.mjs; stale comments
  corrected.

API modernization (new code must use the current protocols):
- All node classes introduced by this commit's tests use the $config()
  protocol instead of legacy static getType/clone/importJSON
  (CardLikeNode, PlainShadowRootNode, ExcludedShadowRootNode,
  TestUpdateDOMTrueHostNode — the latter carrying its instance state via
  afterCloneFrom). The PR's other new classes (CardNode, PullQuoteNode,
  SlotContainerNode and the newer test nodes) already used $config().
- $getSlot drops its unchecked type parameter (the pattern deprecated by
  meta#8661) — as a brand-new @experimental API it returns LexicalNode | null
  and callers narrow with type guards; flow declaration updated and the
  explicit generic call sites converted.
- Every deprecated traversal type parameter in the PR's added code is
  scrubbed (62 call sites across LexicalSlot / LexicalSlotSelection /
  LexicalSlotDfs / SlotClipboardExport tests), using the same
  $assertNodeType(node, $isX) narrowing pattern meta#8667 applied to the
  rest of the test suite; $isTestShadowRootNode /
  $isTestUpdateDOMTrueHostNode guards added to the shared test utils.

Tests: 23 new regression tests across lexical, lexical-clipboard,
lexical-yjs (including real two-doc relay observer tests for first-set,
undo, hostile data, root slots, and the deletion-leak sweep),
lexical-utils, lexical-react, lexical-extension, lexical-devtools-core,
and the playground. Full unit suite: 169 files, 3965 passed. tsc, flow,
prettier, and eslint clean.

Intentionally not addressed here (need product/design decisions rather
than fixes): the SELECT_ALL shadow-root scoping behavior change (kept,
already e2e-pinned; recommend a separate PR + breaking-change note),
per-client slot Map ordering under concurrent distinct-name adds
(inherent to the Y.Map channel design), and a mixed-version rollout
note for pre-slots V1 clients.

https://claude.ai/code/session_0125UE7Cv1mUaM82UH8N1nJX
@etrepum etrepum mentioned this pull request Jun 25, 2026
AlessioGr added a commit to payloadcms/payload that referenced this pull request Sep 11, 2026
Upgrades `lexical` and every installed `@lexical/*` package from
`0.41.0` to `0.50.0` for Payload 3.x. Updates the dependency pins,
lockfile, and `lexicalTargetVersion`.

Also exposes the 15 React entry points added on main in
[#17554](#17554) through
`@payloadcms/richtext-lexical/lexical/react/*`, so custom features can
use these APIs through Payload.

## Breaking changes

**No application changes or data migration are needed when using
Payload's built-in rich text features.**

If you maintain custom rich text features, check that they still compile
and that custom content loads, copies, and pastes correctly. Lexical
removed some older APIs, tightened TypeScript types, and changed how
custom nodes are loaded and copied. Tests that inspect the editor's HTML
may also need updated selectors or snapshots because Lexical adds some
internal markup.

**Do not install `lexical` or `@lexical/*` yourself for use with
Payload.** Remove any direct dependencies you added for the editor and
use Payload's re-exports from `@payloadcms/richtext-lexical/lexical` and
`@payloadcms/richtext-lexical/lexical/*`. Payload supplies the matching
versions; mixing versions can break the editor. This is the existing
[custom feature
requirement](https://payloadcms.com/docs/rich-text/custom-features).

The 3.x Markdown implementation and converter defaults are preserved.
This does not backport the v4 Markdown API changes.

## Breaking changes and Payload migrations

Reviewed
[0.42.0](https://github.com/facebook/lexical/releases/tag/v0.42.0),
[0.43.0](https://github.com/facebook/lexical/releases/tag/v0.43.0),
[0.44.0](https://github.com/facebook/lexical/releases/tag/v0.44.0),
[0.45.0](https://github.com/facebook/lexical/releases/tag/v0.45.0),
[0.46.0](https://github.com/facebook/lexical/releases/tag/v0.46.0),
[0.47.0](https://github.com/facebook/lexical/releases/tag/v0.47.0),
[0.48.0](https://github.com/facebook/lexical/releases/tag/v0.48.0),
[0.49.0](https://github.com/facebook/lexical/releases/tag/v0.49.0),
[0.50.0](https://github.com/facebook/lexical/releases/tag/v0.50.0).
Listed below are breaking API/type changes and behavior changes
explicitly identified as breaking in the release notes. Deprecations and
routine bug fixes are omitted. **Yes** means we had to change Payload
code; **No** means no Payload migration was required.

| Release | Breaking change | Required migration in Payload | Changes
made |
| ------- |
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| ----------------------------- |
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
| 0.42 | [Experimental `hasFitNestedTables` moves out of the table
package into the
playground](meta/lexical#8210). | No | - |
| 0.42 | [The deprecated context-menu plugin is
removed](meta/lexical#8199). | Yes | Removed
the invalid `LexicalContextMenuPlugin` proxy and package export. Custom
consumers must use
`@payloadcms/richtext-lexical/lexical/react/LexicalNodeContextMenuPlugin`
and adapt to its node-context-menu API. |
| 0.43 | [Nested editors delegate asynchronously to their
parent](meta/lexical#8308), restoring the
behavior from before 0.42.0. | No | - |
| 0.45 | [`$getReconciledDirection` now inherits direction through
shadow-root nodes](meta/lexical#8479). | No
| - |
| 0.45 | [Backspace at the start of a non-empty block preserves the
current block type and
formatting](meta/lexical#8493). | No | - |
| 0.45 | [Moving nodes between parents adjusts selection
offsets](meta/lexical#8501). | No | - |
| 0.45 | [Markdown shortcuts can trigger when IME composition
commits](meta/lexical#8503). | No | - |
| 0.45 | [Rich/plain text automatically removes empty inline
elements](meta/lexical#8497). | No | - |
| 0.45 | [Triple-click selection normalization moves from core into
rich/plain text
registration](meta/lexical#8520). Editors
bypassing that registration must add
`NormalizeTripleClickSelectionExtension`. | No | - |
| 0.45 | [`DOMSlot` and the DOM rendering override APIs are
generalized](meta/lexical#8519); playground
`AutocompleteNode` is replaced by `VisibleLineBreakExtension`. | No | -
|
| 0.46 | [`static importJSON` widens its parameter to
`SerializedLexicalNode & Record<string,
unknown>`](#17554). Overrides
using serialized interfaces can fail TypeScript checks. | No | - |
| 0.46 | [Node lookups and traversal no longer infer unchecked subclass
types](meta/lexical#8661). Explicit
unchecked traversal generics are deprecated. | Yes | Removed the upload
drawer’s assumption that a node lookup returns `UploadNode`. Added
`$isUploadNode` before reading or updating upload data. |
| 0.46 | [DOM lookups of the editor root return `RootNode` instead of
`null`](meta/lexical#8588).
Selection-capture handling is also generalized beyond decorators. | No |
- |
| 0.46 | [`insertNodes` preserves leading line breaks, and managed line
breaks receive a DOM
marker](meta/lexical#8615). | No | - |
| 0.46 | [Experimental DOM-import rules register through node
extensions](meta/lexical#8662); the separate
per-package import extensions become deprecated aliases. | No | - |
| 0.46 | [Experimental named slots change the Yjs sync
signature](meta/lexical#8603):
`syncLexicalUpdateToYjsV2__EXPERIMENTAL` gains a `dirtyLeaves`
parameter. | No | - |
| 0.46 | [Copying an element through `NodeSelection` includes its
children](meta/lexical#8603), instead of
copying an empty shell. | No | - |
| 0.46 | [Previously deprecated exports are
removed](meta/lexical#8704): `toggleLink`,
`insertList`, `removeList`, and ContentEditable’s `Props` alias.
Replacements are `$toggleLink`, `$insertList`, `$removeList`, and
`ContentEditableProps`. | No | - |
| 0.47 | [React 17 support is
removed](meta/lexical#8782); React 18 or
later is required. | No | - |
| 0.47 | [Segmented text temporarily switches to normal mode during IME
composition while keeping its
DOM](meta/lexical#8784). Subclasses must
tolerate that temporary mode. | No | - |
| 0.49 | [Built-in nodes adopt
`$config()`](meta/lexical#8640). Direct
static `importJSON`, `importDOM`, `clone`, and `transform`
implementations change; `__type` becomes readonly and automatic node
construction needs zero-argument defaults. Custom static implementations
remain supported. | No | - |
| 0.49 | [`LexicalCommand<T>` checks its payload type more
strictly](meta/lexical#8877).
`LexicalCommand<unknown>` is no longer a safe catch-all. | Yes | Focus
and blur commands were incorrectly registered with `MouseEvent`. Removed
the explicit types so Lexical infers `FocusEvent`. |
| 0.50 | [Named-slot values cannot be replaced with
`LexicalNode.replace()`](meta/lexical#8938).
Block converters also [skip slot
values](meta/lexical#8905). | No | - |
| 0.50 | [Lexical JSON clipboard copying checks
`excludeFromCopy('clone')`, not
`'html'`](meta/lexical#8995). | No | - |

Also updated the copied table action menu for merged-cell bounds, header
toggles, and merge/unmerge selection, and fixed the upload alignment
test’s image selector. Formatting and diff checks pass for the upload
selector fix.

Verified all 15 new entry points through source and published export
maps with runtime imports and TypeScript checks. ESLint and formatting
checks pass.

## Previous Lexical upgrades

- [#15760](#15760) — 0.35.0 →
0.41.0
- [#13715](#13715) — 0.34.0 →
0.35.0
- [#13622](#13622) — 0.28.0 →
0.34.0
mayrang added a commit to mayrang/lexical that referenced this pull request Sep 26, 2026
## Description

`LexicalNode.prototype.getCommonAncestor` is removed entirely, both the
generic and the non-generic form, along with its Flow declaration and its
unit test block.

Current behavior: the method exists and returns `ElementNode | null`, with
a type parameter that is an unchecked cast. The preceding revision of this
PR deprecated that type parameter. Per review, layering a second
deprecation notice on an already-superseded method is worse than removing
it, so the method is dropped instead.

`$getCommonAncestor` (meta#7135) is the replacement and has been available
since February 2025. No in-repo callers remain. The other type-parameter
deprecations from meta#8661 stay as they are — this is the only one of that set
with a full `$` replacement.

AGENTS.md ordinarily forbids removing public APIs; this removal is an
intentional exception at maintainer direction.

Migration is not a direct substitution. The removed method lifted each
operand to an `ElementNode` before delegating, and `$getCommonAncestor`
returns the node itself when both arguments are the same node:

    const aElement = $isElementNode(a) ? a : a.getParent();
    const bElement = $isElementNode(b) ? b : b.getParent();
    const ancestor =
      aElement && bElement
        ? ($getCommonAncestor(aElement, bElement)?.commonAncestor ?? null)
        : null;

Callers that passed a type argument should narrow with a type guard.

## Test plan

### Before

    $ git grep -n 'getCommonAncestor' c23a367 -- \
        packages/lexical/src/LexicalNode.ts packages/lexical/flow/Lexical.js.flow
    packages/lexical/flow/Lexical.js.flow:584:  getCommonAncestor<T extends ElementNode>(node: LexicalNode): T | null;
    packages/lexical/src/LexicalNode.ts:1506:  getCommonAncestor<T extends ElementNode = ElementNode>(

### After

    $ git grep -n 'getCommonAncestor' HEAD -- \
        packages/lexical/src/LexicalNode.ts packages/lexical/flow/Lexical.js.flow
    (no matches)

    $ npx tsc --noEmit
    (no output, exit 0)

    $ pnpm run test-unit
     Test Files  2 failed | 351 passed (353)
          Tests  3 failed | 8613 passed | 1 skipped (8617)
       Duration  27.05s

     FAIL  |scripts-unit| scripts/__tests__/unit/typedocExternalLinks.test.ts > links external types and sources with a flat install
     FAIL  |scripts-unit| scripts/__tests__/unit/typedocExternalLinks.test.ts > links external types and sources with a pnpm install
     FAIL  |unit| packages/lexical-compiler/src/__tests__/unit/subpathImports.test.ts > subpathImports > refreshes mappings and invalidates cached consumers in a Vite dev server

The same three failures reproduce with this change stashed, so they are
pre-existing and unrelated:

    $ git stash && npx vitest --no-watch run typedocExternalLinks.test subpathImports.test
     Test Files  2 failed (2)
          Tests  3 failed | 69 passed (72)

`pnpm run build` and `pnpm run build-types` both exit 0, and the generated
`.d.ts` no longer declares the method. `pnpm run lint-flow` is unchanged
from baseline (62 warnings, 0 errors, none referencing this method).

Browser and e2e matrix jobs were not exercised locally; they run in CI.

Co-Authored-By: Claude Opus 5 <[email protected]>
mayrang added a commit to mayrang/lexical that referenced this pull request Sep 26, 2026
## Description

`LexicalNode.prototype.getCommonAncestor` is removed entirely, both the
generic and the non-generic form, along with its Flow declaration and its
unit test block.

Current behavior: the method exists and returns `ElementNode | null`, with
a type parameter that is an unchecked cast. The preceding revision of this
PR deprecated that type parameter. Per review, layering a second
deprecation notice on an already-superseded method is worse than removing
it, so the method is dropped instead.

`$getCommonAncestor` (meta#7135) is the replacement and has been available
since February 2025. No in-repo callers remain. The other type-parameter
deprecations from meta#8661 stay as they are — this is the only one of that set
with a full `$` replacement.

AGENTS.md ordinarily forbids removing public APIs; this removal is an
intentional exception at maintainer direction.

Migration is not a direct substitution. The removed method lifted each
operand to an `ElementNode` before delegating, and when both arguments are
the same node `$getCommonAncestor` returns a result whose `commonAncestor`
property is that node rather than its parent:

    const aElement = $isElementNode(a) ? a : a.getParent();
    const bElement = $isElementNode(b) ? b : b.getParent();
    const ancestor =
      aElement && bElement
        ? ($getCommonAncestor(aElement, bElement)?.commonAncestor ?? null)
        : null;

Callers that passed a type argument should narrow with a type guard.

## Test plan

### Before

    $ git grep -nE '^[[:space:]]*getCommonAncestor[<(]' c23a367 -- \
        packages/lexical/src/LexicalNode.ts packages/lexical/flow/Lexical.js.flow
    c23a367:packages/lexical/flow/Lexical.js.flow:584:  getCommonAncestor<T extends ElementNode>(node: LexicalNode): T | null;
    c23a367:packages/lexical/src/LexicalNode.ts:1506:  getCommonAncestor<T extends ElementNode = ElementNode>(

### After

    $ git grep -nE '^[[:space:]]*getCommonAncestor[<(]' HEAD -- \
        packages/lexical/src/LexicalNode.ts packages/lexical/flow/Lexical.js.flow
    $ echo $?
    1

    $ npx tsc --noEmit
    $ echo $?
    0

    $ pnpm run test-unit
     Test Files  2 failed | 351 passed (353)
          Tests  3 failed | 8613 passed | 1 skipped (8617)
       Duration  27.05s

     FAIL  |scripts-unit| scripts/__tests__/unit/typedocExternalLinks.test.ts > links external types and sources with a flat install
     FAIL  |scripts-unit| scripts/__tests__/unit/typedocExternalLinks.test.ts > links external types and sources with a pnpm install
     FAIL  |unit| packages/lexical-compiler/src/__tests__/unit/subpathImports.test.ts > subpathImports > refreshes mappings and invalidates cached consumers in a Vite dev server

The same three failures reproduce with this change stashed, so they are
pre-existing and unrelated:

    $ git stash && npx vitest --no-watch run typedocExternalLinks.test subpathImports.test
     Test Files  2 failed (2)
          Tests  3 failed | 69 passed (72)

`pnpm run build` and `pnpm run build-types` both exit 0, and the generated
`.d.ts` no longer declares the method. `pnpm run lint-flow` is unchanged
from baseline (62 warnings, 0 errors, none referencing this method).

Browser and e2e matrix jobs were not exercised locally; they run in CI.

Co-Authored-By: Claude Opus 5 <[email protected]>
mayrang added a commit to mayrang/lexical that referenced this pull request Sep 26, 2026
## Description

`LexicalNode.prototype.getCommonAncestor` is removed entirely, both the
generic and the non-generic form, along with its Flow declaration and its
unit test block.

Current behavior: the method exists and returns `ElementNode | null`, with
a type parameter that is an unchecked cast. The preceding revision of this
PR deprecated that type parameter; per review
(meta#9238 (comment))
the method is removed instead, since layering a second deprecation notice
on an already-superseded method is worse than dropping it.

`$getCommonAncestor` (meta#7135, February 2025) is the replacement. No in-repo
callers remain. meta#8661 deprecated the unsafe type parameters on the node
traversal methods but did not cover this one; those deprecations stay as
they are, because `getCommonAncestor` is the only method of that shape
with a full `$` replacement.

AGENTS.md ordinarily forbids removing public APIs; this removal is an
intentional exception at maintainer direction, linked above.

Migration is not a direct substitution. For a non-element node the removed
method lifted the operand to its parent before delegating, whereas
`$getCommonAncestor` compares the nodes as given and, when both arguments
are the same node, returns a result whose `commonAncestor` is that node.
For an `ElementNode` argument the two already agree.

    const aElement = $isElementNode(a) ? a : a.getParent();
    const bElement = $isElementNode(b) ? b : b.getParent();
    const ancestor =
      aElement && bElement
        ? ($getCommonAncestor(aElement, bElement)?.commonAncestor ?? null)
        : null;

Callers that passed a type argument should narrow with a type guard.

## Test plan

### Before

    $ git grep -nE '^[[:space:]]*getCommonAncestor[<(]' c23a367 -- \
        packages/lexical/src/LexicalNode.ts packages/lexical/flow/Lexical.js.flow
    c23a367:packages/lexical/flow/Lexical.js.flow:584:  getCommonAncestor<T extends ElementNode>(node: LexicalNode): T | null;
    c23a367:packages/lexical/src/LexicalNode.ts:1506:  getCommonAncestor<T extends ElementNode = ElementNode>(

### After

    $ git grep -nE '^[[:space:]]*getCommonAncestor[<(]' HEAD -- \
        packages/lexical/src/LexicalNode.ts packages/lexical/flow/Lexical.js.flow
    $ echo $?
    1

    $ npx tsc --noEmit
    $ echo $?
    0

    $ pnpm run test-unit
     Test Files  2 failed | 351 passed (353)
          Tests  3 failed | 8613 passed | 1 skipped (8617)
       Duration  27.05s

     FAIL  |scripts-unit| scripts/__tests__/unit/typedocExternalLinks.test.ts > links external types and sources with a flat install
     FAIL  |scripts-unit| scripts/__tests__/unit/typedocExternalLinks.test.ts > links external types and sources with a pnpm install
     FAIL  |unit| packages/lexical-compiler/src/__tests__/unit/subpathImports.test.ts > subpathImports > refreshes mappings and invalidates cached consumers in a Vite dev server

Those three are pre-existing. Restoring the three touched files to the
merge-base and rerunning the same two files reproduces them:

    $ git checkout c23a367 -- packages/lexical/src/LexicalNode.ts \
        packages/lexical/flow/Lexical.js.flow \
        packages/lexical/src/__tests__/unit/LexicalNode.test.ts
    $ npx vitest --no-watch run typedocExternalLinks.test subpathImports.test
     Test Files  2 failed (2)
          Tests  3 failed | 69 passed (72)

`pnpm run build` and `pnpm run build-types` both exit 0, and the generated
`.d.ts` no longer declares the method. `pnpm run lint-flow` reports 62
warnings and 0 errors, none referencing this method, matching the
merge-base.

Browser and e2e matrix jobs were not exercised locally; they run in CI.

Co-Authored-By: Claude Opus 5 <[email protected]>
mayrang added a commit to mayrang/lexical that referenced this pull request Sep 26, 2026
## Description

`LexicalNode.prototype.getCommonAncestor` is removed entirely, both the
generic and the non-generic form, along with its Flow declaration and its
unit test block.

Current behavior: the method exists and returns `ElementNode | null`, with
a type parameter that is an unchecked cast. The preceding revision of this
PR deprecated that type parameter; per review
(meta#9238 (comment))
the method is removed instead, since layering a second deprecation notice
on an already-superseded method is worse than dropping it.

`$getCommonAncestor` (meta#7135, February 2025) is the replacement. No in-repo
callers remain. meta#8661 deprecated the unsafe type parameters on the node
traversal methods but did not cover this one; those deprecations stay as
they are, because `getCommonAncestor` is the only method of that shape
with a full `$` replacement.

AGENTS.md ordinarily forbids removing public APIs; this removal is an
intentional exception at maintainer direction, linked above.

Migration is not a direct substitution. For a non-element node the removed
method lifted the operand to its parent before delegating, whereas
`$getCommonAncestor` compares the nodes as given and, when both arguments
are the same node, returns a result whose `commonAncestor` is that node.
For an `ElementNode` argument the two already agree.

    const aElement = $isElementNode(a) ? a : a.getParent();
    const bElement = $isElementNode(b) ? b : b.getParent();
    const ancestor =
      aElement && bElement
        ? ($getCommonAncestor(aElement, bElement)?.commonAncestor ?? null)
        : null;

Callers that passed a type argument should narrow with a type guard.

## Test plan

### Before

    $ git grep -nE '^[[:space:]]*getCommonAncestor[<(]' c23a367 -- \
        packages/lexical/src/LexicalNode.ts packages/lexical/flow/Lexical.js.flow
    c23a367:packages/lexical/flow/Lexical.js.flow:584:  getCommonAncestor<T extends ElementNode>(node: LexicalNode): T | null;
    c23a367:packages/lexical/src/LexicalNode.ts:1506:  getCommonAncestor<T extends ElementNode = ElementNode>(

### After

    $ git grep -nE '^[[:space:]]*getCommonAncestor[<(]' HEAD -- \
        packages/lexical/src/LexicalNode.ts packages/lexical/flow/Lexical.js.flow
    $ echo $?
    1

    $ npx tsc --noEmit
    $ echo $?
    0

    $ pnpm run test-unit
     Test Files  2 failed | 351 passed (353)
          Tests  3 failed | 8613 passed | 1 skipped (8617)
       Duration  27.05s

     FAIL  |scripts-unit| scripts/__tests__/unit/typedocExternalLinks.test.ts > links external types and sources with a flat install
     FAIL  |scripts-unit| scripts/__tests__/unit/typedocExternalLinks.test.ts > links external types and sources with a pnpm install
     FAIL  |unit| packages/lexical-compiler/src/__tests__/unit/subpathImports.test.ts > subpathImports > refreshes mappings and invalidates cached consumers in a Vite dev server

Those three are pre-existing. Restoring the three touched files to the
merge-base and rerunning the same two files reproduces them:

    $ git checkout c23a367 -- packages/lexical/src/LexicalNode.ts \
        packages/lexical/flow/Lexical.js.flow \
        packages/lexical/src/__tests__/unit/LexicalNode.test.ts
    $ npx vitest --no-watch run typedocExternalLinks.test subpathImports.test
     Test Files  2 failed (2)
          Tests  3 failed | 69 passed (72)
    $ git restore --source=HEAD --staged --worktree -- \
        packages/lexical/src/LexicalNode.ts \
        packages/lexical/flow/Lexical.js.flow \
        packages/lexical/src/__tests__/unit/LexicalNode.test.ts
    $ git status --porcelain
    $ echo $?
    0

The build checks below were run after that restore, on a clean tree.

`pnpm run build` and `pnpm run build-types` both exit 0, and the generated
`.d.ts` no longer declares the method. `pnpm run lint-flow` reports 62
warnings and 0 errors, none referencing this method, matching the
merge-base.

Browser and e2e matrix jobs were not exercised locally; they run in CI.

Co-Authored-By: Claude Opus 5 <[email protected]>
zurfyx added a commit that referenced this pull request Oct 15, 2026
…havior changes and deprecations into CHANGELOG.md for v0.23 to v0.52, add an Upgrading page

## Description

Depends on the changesets tooling in #9357.

Past versions in CHANGELOG.md only list commits, so someone upgrading from
an older version cannot find what broke, or how to migrate, without reading
every GitHub release. Future versions get curated sections from changesets;
this gives v0.23.0 to v0.52.0 the same sections.

- Every version from v0.23.0 to v0.52.0 now starts with `### Breaking
  changes` (35 entries), `### Behavior changes` (43) and `### Deprecations`
  (29), each with packages and a PR link. The existing lines are kept,
  unchanged, under `### All changes` (the diff only adds lines).
- Rule, stated in the preamble: a breaking change needs a code change (an
  API removed or renamed, a type that no longer checks, a call that now
  throws) and has `Detect:` and `Migration:`. A behavior change keeps
  building but behaves or renders differently and has `Verify:`. The entries
  come from a verified inventory of those releases, which marked each change
  as manual, mechanical, or runtime-only ("no type or build error points at
  it"). Runtime-only entries are behavior changes, except #7341 (now throws)
  and #8603 (a signature change), which stay breaking.
- v0.50.0: the items its release notes list as "Behavior Changes to Watch"
  (#8765, #8908, #8884, #9059, #9061, #8940, #8283) are behavior changes;
  the listener return-type tightening (#8990), the new invariants (#6483)
  and the two items the release called breaking (#8938, #8995) stay
  breaking. Checked against the v0.50.0 release notes.
- Added the v0.42.0 removal of `@lexical/react/LexicalContextMenuPlugin`
  (#8199; present in the v0.41.0 tag, absent in v0.42.0).
- Deprecations come from a pass over every `@deprecated` tag added between
  consecutive tags v0.22.0 to v0.52.0, each checked against the previous tag
  and attributed with `git log -S`. Each has `Replacement:` and `Removal:`:
  the version that removed it, "no earlier than v0.53.0" for the ones #9316
  removes after v0.52.0, otherwise "not scheduled". Skipped: tags that only
  moved (`trimTextContentFromAnchor`, deprecated before v0.23.0) or restated
  earlier ones (v0.46.0 `HorizontalRulePlugin`, v0.51.0 `getScrollParent`),
  and the v0.47.0 `applyFormatToDom` deprecation that v0.48.0 reversed.
- Entries that mixed a breaking change and a deprecation are split with no
  double counting (#7357, #8360, #8661); #8350 and #8662 only deprecated
  aliases, so they are listed under Deprecations alone.
- `docs/upgrading.md` ("Upgrading" in the sidebar) is a short page: upgrade
  all packages together, read CHANGELOG.md between your version and the
  target (also at `node_modules/lexical/CHANGELOG.md`) or print that range,
  and a copy-paste `AGENTS.md` snippet that points coding agents at the
  installed changelog. Nothing is installed automatically.
- The repository CHANGELOG.md test checks every backfilled entry: `Detect:`
  and `Migration:` on breaking changes, `Verify:` on behavior changes,
  `Replacement:` and a valid `Removal:` on deprecations, a PR link on all.

## Test plan

### Before

```
$ pnpm run changelog:range -- --from 0.49.0 --breaking
Note: v0.50.0, v0.51.0, v0.52.0 have no curated sections (the changelog only lists their commits), so --breaking cannot show what changed there. Run without --breaking to read them in full.
No breaking changes, behavior changes or deprecations recorded after 0.49.0.
```

### After

```
$ git diff --numstat --diff-algorithm=patience HEAD~1 -- CHANGELOG.md
1412	0	CHANGELOG.md

$ pnpm run changelog:range -- --from 0.49.0 --breaking | grep '^## \|^### '
## v0.50.0 (2026-09-02)
### Breaking changes
### Behavior changes
### Deprecations
## v0.51.0 (2026-09-17)
### Breaking changes
### Deprecations
## v0.52.0 (2026-09-27)
### Breaking changes
### Behavior changes
### Deprecations

$ pnpm run changelog:range -- --from 0.49.0 --to 0.50.0 --breaking --json   # (kind, [(pr, behavior)])
[('breaking', [(8938, False), (8995, False), (8990, False), (6483, False)]), ('behavior', [(8765, True), (8908, True), (8884, True), (9059, True), (9061, True), (8940, True), (8283, True)]), ('deprecation', [(8918, False)])]

$ pnpm run test-unit scripts/__tests__/unit/changelog.test.ts scripts/__tests__/unit/changesets.test.ts
      Tests  63 passed (63)

$ pnpm -C packages/lexical-website run docusaurus build
[SUCCESS] Generated static files in "build".
```
zurfyx added a commit that referenced this pull request Oct 15, 2026
…havior changes and deprecations into CHANGELOG.md for v0.23 to v0.52, add an Upgrading page

## Description

Depends on the changesets tooling in #9357.

Past versions in CHANGELOG.md only list commits, so someone upgrading from
an older version cannot find what broke, or how to migrate, without reading
every GitHub release. Future versions get curated sections from changesets;
this gives v0.23.0 to v0.52.0 the same sections.

- Every version from v0.23.0 to v0.52.0 now starts with `### Breaking
  changes` (35 entries), `### Behavior changes` (43) and `### Deprecations`
  (29), each with packages and a PR link. The existing lines are kept,
  unchanged, under `### All changes` (the diff only adds lines).
- Rule, stated in the preamble: a breaking change needs a code change (an
  API removed or renamed, a type that no longer checks, a call that now
  throws) and has `Detect:` and `Migration:`. A behavior change keeps
  building but behaves or renders differently and has `Verify:`. The entries
  come from a verified inventory of those releases, which marked each change
  as manual, mechanical, or runtime-only ("no type or build error points at
  it"). Runtime-only entries are behavior changes, except #7341 (now throws)
  and #8603 (a signature change), which stay breaking.
- v0.50.0: the items its release notes list as "Behavior Changes to Watch"
  (#8765, #8908, #8884, #9059, #9061, #8940, #8283) are behavior changes;
  the listener return-type tightening (#8990), the new invariants (#6483)
  and the two items the release called breaking (#8938, #8995) stay
  breaking. Checked against the v0.50.0 release notes.
- Added the v0.42.0 removal of `@lexical/react/LexicalContextMenuPlugin`
  (#8199; present in the v0.41.0 tag, absent in v0.42.0).
- Deprecations come from a pass over every `@deprecated` tag added between
  consecutive tags v0.22.0 to v0.52.0, each checked against the previous tag
  and attributed with `git log -S`. Each has `Replacement:` and `Removal:`:
  the version that removed it, "no earlier than v0.53.0" for the ones #9316
  removes after v0.52.0, otherwise "not scheduled". Skipped: tags that only
  moved (`trimTextContentFromAnchor`, deprecated before v0.23.0) or restated
  earlier ones (v0.46.0 `HorizontalRulePlugin`, v0.51.0 `getScrollParent`),
  and the v0.47.0 `applyFormatToDom` deprecation that v0.48.0 reversed.
- Entries that mixed a breaking change and a deprecation are split with no
  double counting (#7357, #8360, #8661); #8350 and #8662 only deprecated
  aliases, so they are listed under Deprecations alone.
- `docs/upgrading.md` ("Upgrading" in the sidebar) is a short page: upgrade
  all packages together, read CHANGELOG.md between your version and the
  target (also at `node_modules/lexical/CHANGELOG.md`) or print that range,
  and a copy-paste `AGENTS.md` snippet that points coding agents at the
  installed changelog. Nothing is installed automatically.
- The repository CHANGELOG.md test checks every backfilled entry: `Detect:`
  and `Migration:` on breaking changes, `Verify:` on behavior changes,
  `Replacement:` and a valid `Removal:` on deprecations, a PR link on all.

## Test plan

### Before

```
$ pnpm run changelog:range -- --from 0.49.0 --breaking
Note: v0.50.0, v0.51.0, v0.52.0 have no curated sections (the changelog only lists their commits), so --breaking cannot show what changed there. Run without --breaking to read them in full.
No breaking changes, behavior changes or deprecations recorded after 0.49.0.
```

### After

```
$ git diff --numstat --diff-algorithm=patience HEAD~1 -- CHANGELOG.md
1412	0	CHANGELOG.md

$ pnpm run changelog:range -- --from 0.49.0 --breaking | grep '^## \|^### '
## v0.50.0 (2026-09-02)
### Breaking changes
### Behavior changes
### Deprecations
## v0.51.0 (2026-09-17)
### Breaking changes
### Deprecations
## v0.52.0 (2026-09-27)
### Breaking changes
### Behavior changes
### Deprecations

$ pnpm run changelog:range -- --from 0.49.0 --to 0.50.0 --breaking --json   # (kind, [(pr, behavior)])
[('breaking', [(8938, False), (8995, False), (8990, False), (6483, False)]), ('behavior', [(8765, True), (8908, True), (8884, True), (9059, True), (9061, True), (8940, True), (8283, True)]), ('deprecation', [(8918, False)])]

$ pnpm run test-unit scripts/__tests__/unit/changelog.test.ts scripts/__tests__/unit/changesets.test.ts
      Tests  63 passed (63)

$ pnpm -C packages/lexical-website run docusaurus build
[SUCCESS] Generated static files in "build".
```
etrepum added a commit to etrepum/lexical that referenced this pull request Oct 27, 2026
…e: Remove obsolete traversal documentation and rejection tests

## Description

Remove the removed-overload example and migration inventory from the traversal guide, retaining supported guard examples. Remove stale source comments and reword historical changelog entries while preserving PR attribution. Delete the newly added Flow fixture and rejected-generic TypeScript assertions; keep existing traversal coverage, supported-call migrations, and runtime APIs unchanged.

## Test plan

### Before

Documentation/comment audit at the previous head:

```text
packages/lexical-website/docs/concepts/traversals.md:20: getFirstChild<
packages/lexical/src/LexicalNode.ts:1293: deprecated generic signatures from meta#8661
```

### After

Documentation/comment audit of all tracked text files:

```text
Scanned 2514 tracked text files, 191 documentation files, 31508 source comment blocks.
No removed traversal signatures or obsolete deprecation references remain in documentation or source comments.
```

`pnpm run tsc-test`, `pnpm run tsc`, and `pnpm run tsc-website` (exit 0):

```text
$ tsc -p ./tsconfig.test.json
$ tsc
$ tsc -p tsconfig.json
```

`pnpm run flow` (exit 0):

```text
Running Flow...
Found 0 errors
```

`pnpm exec vitest --project unit --no-watch packages/lexical/src/__tests__/unit/LexicalNode.test.ts`:

```text
 Test Files  1 passed (1)
      Tests  135 passed (135)
```

`pnpm run build` and `pnpm run build:doc-examples` (exit 0):

```text
Built 5 documentation examples.
```

`pnpm run build-docs` (exit 0; existing TypeDoc, bundle, and static-generation warnings):

```text
[SUCCESS] Generated static files in "build".
```

Changed-file ESLint and `git diff --check`: exit 0.
Changed-file Prettier (Markdown is excluded by the repository configuration):

```text
Checking formatting...
All matched files use Prettier code style!
```

No new tests added. Full browser/E2E suites not rerun locally.
zurfyx added a commit that referenced this pull request Oct 28, 2026
…havior changes and deprecations into CHANGELOG.md for v0.23 to v0.52, add an Upgrading page

Depends on the changesets tooling in #9357.

Past versions in CHANGELOG.md only list commits, so someone upgrading from
an older version cannot find what broke, or how to migrate, without reading
every GitHub release. Future versions get curated sections from changesets;
this gives v0.23.0 to v0.52.0 the same sections.

- Every version from v0.23.0 to v0.52.0 now starts with `### Breaking
  changes` (35 entries), `### Behavior changes` (43) and `### Deprecations`
  (29), each with packages and a PR link. The existing lines are kept,
  unchanged, under `### All changes` (the diff only adds lines).
- Rule, stated in the preamble: a breaking change needs a code change (an
  API removed or renamed, a type that no longer checks, a call that now
  throws) and has `Detect:` and `Migration:`. A behavior change keeps
  building but behaves or renders differently and has `Verify:`. The entries
  come from a verified inventory of those releases, which marked each change
  as manual, mechanical, or runtime-only ("no type or build error points at
  it"). Runtime-only entries are behavior changes, except #7341 (now throws)
  and #8603 (a signature change), which stay breaking.
- v0.50.0: the items its release notes list as "Behavior Changes to Watch"
  (#8765, #8908, #8884, #9059, #9061, #8940, #8283) are behavior changes;
  the listener return-type tightening (#8990), the new invariants (#6483)
  and the two items the release called breaking (#8938, #8995) stay
  breaking. Checked against the v0.50.0 release notes.
- Added the v0.42.0 removal of `@lexical/react/LexicalContextMenuPlugin`
  (#8199; present in the v0.41.0 tag, absent in v0.42.0).
- Deprecations come from a pass over every `@deprecated` tag added between
  consecutive tags v0.22.0 to v0.52.0, each checked against the previous tag
  and attributed with `git log -S`. Each has `Replacement:` and `Removal:`:
  the version that removed it, "no earlier than v0.53.0" for the ones #9316
  removes after v0.52.0, otherwise "not scheduled". Skipped: tags that only
  moved (`trimTextContentFromAnchor`, deprecated before v0.23.0) or restated
  earlier ones (v0.46.0 `HorizontalRulePlugin`, v0.51.0 `getScrollParent`),
  and the v0.47.0 `applyFormatToDom` deprecation that v0.48.0 reversed.
- Entries that mixed a breaking change and a deprecation are split with no
  double counting (#7357, #8360, #8661); #8350 and #8662 only deprecated
  aliases, so they are listed under Deprecations alone.
- `docs/upgrading.md` ("Upgrading" in the sidebar) is a short page: upgrade
  all packages together, read CHANGELOG.md between your version and the
  target (also at `node_modules/lexical/CHANGELOG.md`) or print that range,
  and a copy-paste `AGENTS.md` snippet that points coding agents at the
  installed changelog. Nothing is installed automatically.
- The repository CHANGELOG.md test checks every backfilled entry: `Detect:`
  and `Migration:` on breaking changes, `Verify:` on behavior changes,
  `Replacement:` and a valid `Removal:` on deprecations, a PR link on all.

```
$ pnpm run changelog:range -- --from 0.49.0 --breaking
Note: v0.50.0, v0.51.0, v0.52.0 have no curated sections (the changelog only lists their commits), so --breaking cannot show what changed there. Run without --breaking to read them in full.
No breaking changes, behavior changes or deprecations recorded after 0.49.0.
```

```
$ git diff --numstat --diff-algorithm=patience HEAD~1 -- CHANGELOG.md
1412	0	CHANGELOG.md

$ pnpm run changelog:range -- --from 0.49.0 --breaking | grep '^## \|^### '

$ pnpm run changelog:range -- --from 0.49.0 --to 0.50.0 --breaking --json   # (kind, [(pr, behavior)])
[('breaking', [(8938, False), (8995, False), (8990, False), (6483, False)]), ('behavior', [(8765, True), (8908, True), (8884, True), (9059, True), (9061, True), (8940, True), (8283, True)]), ('deprecation', [(8918, False)])]

$ pnpm run test-unit scripts/__tests__/unit/changelog.test.ts scripts/__tests__/unit/changesets.test.ts
      Tests  63 passed (63)

$ pnpm -C packages/lexical-website run docusaurus build
[SUCCESS] Generated static files in "build".
```
zurfyx added a commit that referenced this pull request Nov 2, 2026
…s in CHANGELOG.md by the call shapes they break, and add the missing v0.48 list Backspace behavior change

## Description

Three backfilled CHANGELOG.md entries did not tell people upgrading who is affected or what to change:

- v0.46.0, #8661: the breaking entry said traversal methods "return the base node type" and only named annotated assignments. It did not say that the methods (and `$getNodeByKey` / `$getNodeByKeyOrThrow`) gained a non-generic first overload, so a call without a type argument that used to infer `T` from where its result went (a function argument, a return value, an annotated variable or array) now returns `LexicalNode` and stops compiling. Detect now names those call shapes and the TypeScript error, Migration shows the function-argument case, and the matching deprecation entry now has its own Detect and says the overloads were removed from TypeScript in v0.53.0 (#9479), while the Flow declarations keep them after #9529, instead of "Removal: not scheduled".
- v0.49.0, #8877: the entry said `LexicalCommand<T>` is invariant, but Detect only named `LexicalCommand<unknown>` and explicit generics. A `registerCommand` listener whose parameter annotation is narrower or wider than the payload (for example `(event: KeyboardEvent) => ...` for `KEY_ENTER_COMMAND`, whose payload is `KeyboardEvent | null`), or a helper typed `LexicalCommand<KeyboardEvent>` called with that command, also stops compiling. Detect lists these shapes and the error, and Migration shows inferred listeners and a generic helper.
- v0.48.0, #8829: not listed at all. `registerList` handles Backspace at `COMMAND_PRIORITY_BEFORE_EDITOR`, before rich text: at the start of a top-level item it turns the item into a paragraph and splits the list, where it used to join it to the item above. It is now a behavior change with a Verify line. `ListItemNode.collapseAtStart` also widened its return type from `true` to `boolean`; the entry says why that is not filed as breaking.

To keep this from recurring, `.changeset/README.md` gets a "Type signature changes" section: a type change that can make existing call sites stop compiling is `[breaking]` even when it only deprecates something, and its Detect names the call shapes, including callers that rely on an inferred type argument. AGENTS.md and CONTRIBUTING.md, which already summarize the changeset format, get one paragraph each. `pnpm run check-changesets` now warns (without failing) when a `[deprecation]` or `[chore]` entry mentions a type parameter, overload, generic, return or payload type, or signature and has no `Detect:` paragraph. The pattern also covers "type params", "branded", "invariant", "narrowed return/payload" and "now returns". Neither the pending changesets nor the curated `[deprecation]` and Other entries in CHANGELOG.md trigger it.

Out of scope: `packages/lexical-list/flow/LexicalList.js.flow` still declares `collapseAtStart(selection: RangeSelection): true`. Changing it is a published Flow type change that needs its own changeset.

## Changeset

None needed: documentation and changeset tooling only.

## Test plan

The new CHANGELOG.md wording was checked against the declarations at the v0.45.0, v0.46.0, v0.48.0 and v0.49.0 tags, and the TypeScript errors and the Migration snippets were compiled against the current sources. The list Backspace change was checked with a scratch unit test (not committed) that presses Backspace at the start of the second of three items, with and without `ListExtension`: `["list:first","paragraph:second","list:third"]` with it, and `["list:firstsecond|third"]` with rich text alone, which is what v0.47 did.

### Before

With the test changes applied but not the CHANGELOG.md and `entry.mjs` changes:

```
$ pnpm vitest run scripts/__tests__/unit/changesets.test.ts scripts/__tests__/unit/changelog.test.ts
     × warns when a deprecation or chore changes types without Detect 4ms
     × parses the repository CHANGELOG.md 15ms
 FAIL  |scripts-unit| scripts/__tests__/unit/changelog.test.ts > parseChangelog > parses the repository CHANGELOG.md
AssertionError: expected { behavior: 43, breaking: 35, …(1) } to deeply equal { behavior: 44, breaking: 35, …(1) }
 FAIL  |scripts-unit| scripts/__tests__/unit/changesets.test.ts > changeset entry format > warns when a deprecation or chore changes types without Detect
AssertionError: expected { errors: [], warnings: [] } to deeply equal { errors: [], warnings: [ …(1) ] }
 Test Files  2 failed (2)
      Tests  2 failed | 63 passed (65)
```

### After

```
$ pnpm vitest run scripts/__tests__/unit/changesets.test.ts scripts/__tests__/unit/changelog.test.ts
 Test Files  2 passed (2)
      Tests  65 passed (65)

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

Prettier and ESLint pass on the changed files.
zurfyx added a commit that referenced this pull request Nov 4, 2026
…raversal and v0.48 list Backspace changelog entries

## Description

Review follow-ups for the changelog entries this pull request rewrites:

- v0.48.0, #8829: nested list items were already outdented by `@lexical/rich-text` before #8829 (a nested `ListItemNode` reports its depth as its indent). The entry now says what changed: Backspace at the start of a top-level item used to join it to the block above, either the previous item or a paragraph before the list, and now turns it into a paragraph.
- v0.46.0, #8661: Detect quotes the TypeScript errors each call shape produces (TS2322, TS2345, and TS2740 for a return value).
- `.changeset/README.md`: the type-signature example uses `getFirstChildOrThrow()`, since `getFirstChild()` returns `T | null` and its argument case already failed under `strict`.

## Test plan

The quoted errors come from compiling the four call shapes (annotated `getFirstChild()`, annotated `getChildren()`, `getFirstChildOrThrow()` as an argument, and as a return value) against the current declarations, whose non-generic overloads are the ones v0.46.0 added:

```
t.ts(5,7): error TS2322: Type 'LexicalNode | null' is not assignable to type 'ParagraphNode | null'.
t.ts(6,7): error TS2322: Type 'LexicalNode[]' is not assignable to type 'ListItemNode[]'.
t.ts(7,12): error TS2345: Argument of type 'LexicalNode' is not assignable to parameter of type 'ListNode'.
t.ts(9,3): error TS2740: Type 'LexicalNode' is missing the following properties from type 'ListNode': __tag, __start, __listType, getTag, and 68 more.
```

A scratch unit test (not committed) pressing Backspace at the start of the first item of a list that follows a paragraph prints `["paragraph:para","paragraph:first","list:second"]` with `ListExtension` and `["paragraph:parafirst","list:second"]` with rich text alone.

### Before

Same tests as the previous commit:

```
$ pnpm vitest run scripts/__tests__/unit/changesets.test.ts scripts/__tests__/unit/changelog.test.ts
 Test Files  2 passed (2)
      Tests  65 passed (65)
```

### After

```
$ pnpm vitest run scripts/__tests__/unit/changesets.test.ts scripts/__tests__/unit/changelog.test.ts
 Test Files  2 passed (2)
      Tests  65 passed (65)

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

This branch was successfully deployed

2 active deployments
Preview – lexical — 567c33b8 Deployed Jun 9, 2026 by vercel[bot]
Preview – lexical-playground — 567c33b8 Deployed Jun 9, 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.

3 participants