Skip to content

[lexical] Documentation: Add TSDoc for LexicalNodeReplacement and withKlass - #8471

Merged
etrepum merged 3 commits into
meta:mainfrom
markselby9:docs/6398-lexical-node-replacement-tsdoc
May 7, 2026
Merged

etrepum merged 3 commits into
meta:mainfrom
markselby9:docs/6398-lexical-node-replacement-tsdoc

Conversation

@markselby9

Copy link
Copy Markdown
Contributor

Summary

Addresses the API-documentation portion of #6398 — the concept page was added in #6890, but LexicalNodeReplacement itself had no TSDoc, so readers who hit the runtime "withKlass will be required in a future version" warning had nothing in-source to explain what to pass or why.

This PR adds TSDoc on the type and each of its three fields:

  • replace — the core node class whose instances should be replaced.
  • with — factory called whenever replace is constructed; returns the substituted node.
  • withKlass — explains why it matters: LexicalEditor.registerNodeTransform and LexicalEditor.registerMutationListener subscriptions targeting the original class only continue to fire on the substituted instances if withKlass is provided. Notes the future-required status that the runtime warning at line 772 hints at.

The type-level TSDoc links to the existing Node Replacement concept page rather than duplicating the full example here.

Scope

Pure docstring change — no logic, no behavior change, no test changes. Single file (packages/lexical/src/LexicalEditor.ts), +26 / -0.

The stackblitz-example sub-task that was discussed in the issue thread (and attempted in the now-closed #6930) is intentionally not in scope here; this PR addresses only the unchecked "API documentation is still missing" checkbox.

Closes #6398

…hKlass

Closes meta#6398. The concept page was added in meta#6890 but the API surface had
no TSDoc, leaving readers who hit the runtime "withKlass will be required
in a future version" warning without an in-source explanation. Adds
TSDoc on the type and each of its three fields (replace, with, withKlass),
explains why withKlass matters for node transforms and mutation listeners,
and links to the existing concept page for the full example.
@vercel

vercel Bot commented May 7, 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 May 7, 2026 2:35am
lexical-playground Ready Ready Preview, Comment May 7, 2026 2:35am

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 May 7, 2026
Pre-emptive polish before maintainer review. Two correctness fixes and a
trim:
- 'with' now correctly says it's invoked by $applyNodeReplacement (which
  the $create* factories call) — not "whenever 'replace' is constructed",
  since direct `new` bypasses it. Adds the must-be-instance-of-withKlass
  invariant.
- 'withKlass' splits transforms (fan out) from mutation listeners
  (redirect) — registerMutationListener resolves through the replacement
  chain rather than firing on both, so collapsing them was misleading.
  Also adds the prototype-extends-replace invariant and tightens the
  future-required wording.
- Type-level paragraph drops the redundant CreateEditorArgs cross-link.
Pre-emptive style polish: drop internal-implementation references and
multi-clause hedging in favor of declarative user-facing prose.
- Drop the $applyNodeReplacement helper name from the 'with' doc
- Drop the "Direct new bypasses" failure-mode footnote
- Collapse the transform-vs-mutation-listener distinction into one
  user-facing clause (both register on the replacement)
- Tighten the future-required wording to a single sentence
- Drop "(asserted in dev)" implementation noise on the must-extend rule
@etrepum
etrepum added this pull request to the merge queue May 7, 2026
Merged via the queue into meta:main with commit b7e20ae May 7, 2026
14 checks passed
@etrepum etrepum mentioned this pull request May 28, 2026

This branch was successfully deployed

2 active deployments
Preview – lexical — 0a2d0cc5 Deployed May 7, 2026 by vercel[bot]
Preview – lexical-playground — 0a2d0cc5 Deployed May 7, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: Document the withKlass option for node replacement

2 participants