[lexical-website] Documentation Update: guard node references in later callbacks - #9268
Open
ZedingZhang wants to merge 1 commit into
Open
ZedingZhang wants to merge 1 commit into
ZedingZhang wants to merge 1 commit into
Conversation
…r callbacks ## Description A callback can retain a non-null node reference after the node has been removed from the editor state. The key-management FAQ mentions the possible error but does not show where to check the node before using it. Document both supported patterns: resolve a captured NodeKey in the later update, or guard an existing node reference with isAttached() inside that update. Explain the difference between a missing key and a detached node, keep checks and usage in the same read/update context, and link the examples from the editor-state guide. Clarify that the constructor/clone guidance concerns direct __key access, not application-level key lookup. Related to facebook#9111. This addresses the suggested documentation improvement; it does not implement the proposed lint rule. Prepared and validated with Codex assistance. ## Test plan ### Before A local headless probe against current source reproduced the removed-node error from unguarded getLatest() access: ```text REPRO key: unguarded access throws after removal REPRO reference: unguarded access throws after removal ``` ### After Extracted both TypeScript snippets from the Markdown and checked them against the current source with TypeScript and Prettier. Executed them in a local headless probe: ```text PASS key: selects attached node PASS key: resolves latest node version PASS key: removed node is a no-op without throwing PASS reference: selects attached node PASS reference: resolves latest node version PASS reference: removed node is a no-op without throwing ``` Website TypeScript checking and the package build passed. Docusaurus generated both edited pages; checked that the new heading, code snippets, and cross-page anchor are present in the generated HTML. `git diff --check` passed. Full website build is not green locally on Windows / Node 24.19.0: `pnpm -C packages/lexical-website run build` stops in the existing dev-example script with `Error: spawnSync npx ENOENT`. After running those Vite builds directly and building the documentation examples, `pnpm -C packages/lexical-website run docusaurus build` renders the pages but fails broken-link validation because TypeDoc rejects the existing backslash-separated entry-point paths (`Glob inputs to TypeDoc may not use Windows path separators`) and leaves API pages missing. No build configuration was changed. Linux/macOS builds were not run locally.
ZedingZhang
requested review from
acywatson,
etrepum,
fantactuka,
ivailop7 and
potatowagon
as code owners
September 29, 2026 06:35
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
etrepum
reviewed
Sep 30, 2026
etrepum
left a comment
Collaborator
There was a problem hiding this comment.
I don't think this is necessarily the best guidance, as long as you check isAttached first it's fine to use a reference even if the node is not in the current NodeMap. The implementation of isAttached has no dependency on getLatest or getWritable and will never throw.
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
A callback can retain a non-null node reference after the node has been removed from the editor state. The key-management FAQ mentions the possible error but does not show where to check the node before using it.
Document both supported patterns: resolve a captured NodeKey in the later update, or guard an existing node reference with isAttached() inside that update. Explain the difference between a missing key and a detached node, keep checks and usage in the same read/update context, and link the examples from the editor-state guide. Clarify that the constructor/clone guidance concerns direct __key access, not application-level key lookup.
Related to #9111. This addresses the suggested documentation improvement; it does not implement the proposed lint rule.
Prepared and validated with Codex assistance.
Test plan
Before
A local headless probe against current source reproduced the removed-node error from unguarded getLatest() access:
After
Extracted both TypeScript snippets from the Markdown and checked them against the current source with TypeScript and Prettier. Executed them in a local headless probe:
Website TypeScript checking and the package build passed. Docusaurus generated both edited pages; checked that the new heading, code snippets, and cross-page anchor are present in the generated HTML.
git diff --checkpassed.Full website build is not green locally on Windows / Node 24.19.0:
pnpm -C packages/lexical-website run buildstops in the existing dev-example script withError: spawnSync npx ENOENT. After running those Vite builds directly and building the documentation examples,pnpm -C packages/lexical-website run docusaurus buildrenders the pages but fails broken-link validation because TypeDoc rejects the existing backslash-separated entry-point paths (Glob inputs to TypeDoc may not use Windows path separators) and leaves API pages missing. No build configuration was changed. Linux/macOS builds were not run locally.