Repository navigation
[lexical] Breaking change: Remove LexicalNode.getCommonAncestor - #9238
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
I think in this case it's better to simply remove it rather than add a second way that this method is deprecated, especially considering the amount of time it's been deprecated. |
4aa1592 to
d1acc38
Compare
|
Makes sense — removing it entirely rather than deprecating it twice. Retitled the commit as well, since the changelog is generated from commit subjects. The other type-parameter deprecations from #8661 stay as they are; The migration note in the description covers the element-lifting difference — a direct swap to |
d1acc38 to
01962da
Compare
01962da to
2aa94af
Compare
## 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]>
2aa94af to
fb45af1
Compare
## 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]>
fb45af1 to
130a5be
Compare
…18397) _Written with AI_ Upgrades `lexical` and every installed `@lexical/*` package from `0.50.0` to `0.52.0` for Payload 4.x (`main`), and pinned `tsx` dependencies from `4.22.4` to `4.23.15`. Removes the native-loader workaround no longer needed with the new tsx version. Also fixes duplicate image uploads triggered by repeated node transforms in Lexical 0.52. CI fixes update the keyboard-navigation expectation and correct an existing auth-test parameter error that blocked integration tests. Fixes #17757 3.x counterpart: #18398. ## Why this fixes the CLI failure With Payload 3.90.1 on Node 22.22.0, importing a config that included `lexicalEditor()` could leave CLI startup pending before the config or target script was evaluated. The process then exited 0 with no output and left a pending PostgreSQL migration unapplied. Previously, Payload started the CLI with `void start()`, and an unresolved promise alone does not keep Node's event loop alive. Lexical 0.50's Node entry points select their build with top-level `await import(...)`, which is probably what caused it. Lexical has shipped ESM-only packages since **0.51**, using static imports instead of those asynchronous Node wrappers. Upgrading to 0.52 fixes this issue. Also removes the `module.registerHooks = undefined` workaround for #16949. tsx 4.23.15 [excludes bare built-ins from namespace inheritance](privatenumber/tsx@38e1588), following its [Node 24 `tsImport` bridge fix](privatenumber/tsx@6e5236b). ## CLI exit codes CLI startup is now awaited at the top level in all three loader paths: tsx, SWC, and disabled transpilation. If an import never settles and Node runs out of work, Node reports an unsettled top-level await and exits 13. Successful commands still exit 0, and command-specific failure codes are preserved. ## Breaking changes Rich-text data keeps its existing format. No database migration is needed. Payload's built-in features have been updated, but your own TypeScript code or custom features may need changes: - **Generic types:** `SerializedEditorState<T>`, `SerializedElementNode<T>`, and `SerializedRootNode<T>` no longer accept `<T>`. Remove it if the base node type is enough, or use Payload's `TypedEditorState<T>` for documents with your own node types. Without `<T>`, children are still `SerializedLexicalNode[]`. - **Export types:** `ReturnType<Node['exportJSON']>` can now make fields such as `version` and `url` optional. Use the node's explicit serialized type, such as `SerializedLinkNode`, when you need the full format. Normal `node.exportJSON()` calls still return full JSON. - **Selection listeners:** `SELECTION_CHANGE_COMMAND` now fires before the DOM is updated. If your custom listener reads the DOM, defer that work with `$onUpdate(() => editor.read('latest', callback))`. - **Saved node references:** If you keep a node reference across an editor update, call `node.getLatest().exportJSON()` to export its current values. The type changes also affect imports through `@payloadcms/richtext-lexical/lexical` and its subpaths. Payload's `TypedEditorState<T>` and its own serialized node types keep their generic APIs for this upgrade. Keep importing Lexical through Payload's re-exports; do not install a separate Lexical version. See the [custom feature documentation](https://payloadcms.com/docs/rich-text/custom-features). The table below also lists removed APIs that may affect custom features. `LexicalComposer` is deprecated but still available. ## Breaking changes and Payload migrations Reviewed [0.51.0](https://github.com/facebook/lexical/releases/tag/v0.51.0) and [0.52.0](https://github.com/facebook/lexical/releases/tag/v0.52.0), including the serialization declarations. **Yes** means Payload code needed adaptation; **No** means no Payload migration was required. | Release | Breaking change | Required migration in Payload | Changes made | | ------- | --------------- | ----------------------------- | ------------ | | 0.51 | [npm packages are ESM only](meta/lexical#9127); older CommonJS consumers must use dynamic imports. | No | Payload already uses ESM. This removes the asynchronous Lexical wrapper involved in the CLI reproducer. | | 0.51 | [Serialization schemas and compact export](meta/lexical#8602) add `exportJSON` overloads and remove the `SerializedEditorState`, `SerializedElementNode`, and `SerializedRootNode` generics. `ReturnType` can now infer compact, partial JSON. | Yes | Infer the full-format overload for node hooks, validation and population while preserving custom nodes' literal `type` discriminants. Update `hasText` to the non-generic editor-state type. | | 0.51 | [`exportJSON` can serialize a retained instance without calling `getLatest()`](meta/lexical#8602). | No | Audited Payload's clipboard and Markdown call sites: they serialize nodes obtained from the current selection/tree, without an intervening mutation. Custom callers holding stale references should use `node.getLatest().exportJSON()`. | | 0.51 | [Deprecated Prism re-exports are removed from `@lexical/code`](meta/lexical#9141). | No | Payload does not consume the removed exports. | | 0.52 | [`SELECTION_CHANGE_COMMAND` runs before DOM reconciliation](meta/lexical#9219), including node and table selections. | Yes | Defer link popup, inline toolbar and decorator DOM work with `$onUpdate` and `editor.read('latest', ...)`. Keep nested decorator updates with their own editor. The table menu already defers DOM reads. | | 0.52 | [Default HTML export honors `DOMRenderExtension` `$createDOM` overrides](meta/lexical#9231). | No | Payload does not configure these extension overrides; existing converter tests pass. | | 0.52 | [`LexicalNode.getCommonAncestor` is removed](meta/lexical#9238). | No | No Payload call sites. Custom consumers can use `$getCommonAncestor`, accounting for its different handling of non-element nodes. | React package entry points were compared against 0.50.0; no Payload proxy exports need adding or removing. ## Previous Lexical upgrades - [#18149](#18149) — 0.48.0 → 0.50.0 - [#17554](#17554) — 0.45.0 → 0.48.0 - [#17064](#17064) — 0.41.0 → 0.45.0
Description
LexicalNode.prototype.getCommonAncestoris removed entirely, both thegeneric and the non-generic form, along with its Flow declaration and its
unit test block.
Current behavior: the method exists and returns
ElementNode | null, witha type parameter that is an unchecked cast. The preceding revision of this
PR deprecated that type parameter; per review
(#9238 (comment))
the method is removed instead, since layering a second deprecation notice
on an already-superseded method is worse than dropping it.
$getCommonAncestor(#7135, February 2025) is the replacement. No in-repocallers remain. #8661 deprecated the unsafe type parameters on the node
traversal methods but did not cover this one; those deprecations stay as
they are, because
getCommonAncestoris the only method of that shapewith 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
$getCommonAncestorcompares the nodes as given and, when both argumentsare the same node, returns a result whose
commonAncestoris that node.For an
ElementNodeargument the two already agree.Callers that passed a type argument should narrow with a type guard.
Test plan
Before
After
Those three are pre-existing. Restoring the three touched files to the
merge-base and rerunning the same two files reproduces them:
The build checks below were run after that restore, on a clean tree.
pnpm run buildandpnpm run build-typesboth exit 0, and the generated.d.tsno longer declares the method.pnpm run lint-flowreports 62warnings and 0 errors, none referencing this method, matching the
merge-base.
Browser and e2e matrix jobs were not exercised locally; they run in CI.