Repository navigation
[lexical-website] Documentation Update: getElementByKey returns a DOM element, not a node - #9192
Merged
etrepum merged 1 commit intoSep 22, 2026
Conversation
… element, not a node
## Description
The Key-Related APIs snippet in the Key Management guide presents
`editor.getElementByKey(key)` as a way to "Get node by key", and declares
`const node` twice in the same block:
```typescript
// Get node by key
const node = editor.getElementByKey(key);
const node = $getNodeByKey(key);
```
`getElementByKey` returns `HTMLElement | null` — the reconciled DOM element for
that key, not the `LexicalNode` — and the duplicate `const node` would not run.
The following lines then call `node.getLatest()` / `node.getWritable()`, which
are node methods, so as written they are applied to a DOM element.
This separates the two lookups and gives each its own name and comment.
## Test plan
Documentation-only change (markdown is excluded from prettier via
`.prettierignore`), so the check is that each documented call is described by
what it returns.
### Before
```
$ sed -n '108,112p' packages/lexical-website/docs/concepts/key-management.md
```typescript
// Get node by key
const node = editor.getElementByKey(key);
const node = $getNodeByKey(key);
$ grep -n -A2 " getElementByKey(" packages/lexical/src/LexicalEditor.ts
1727: getElementByKey(key: NodeKey): HTMLElement | null {
1728- return this._keyToDOMMap.get(key) || null;
1729- }
```
The element lookup is labelled as a node lookup, and `const node` is redeclared.
### After
```
$ sed -n '108,114p' packages/lexical-website/docs/concepts/key-management.md
```typescript
// Get node by key
const node = $getNodeByKey(key);
// Get the DOM element a node key is reconciled to
const element = editor.getElementByKey(key);
```
`node` now comes from `$getNodeByKey` (`packages/lexical/src/LexicalUtils.ts:681`),
so the `node.getLatest()` / `node.getWritable()` lines that follow apply to a
`LexicalNode`.
potatowagon
requested review from
acywatson,
etrepum,
fantactuka,
ivailop7 and
zurfyx
as code owners
September 22, 2026 11:35
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
etrepum
approved these changes
Sep 22, 2026
Merged
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The Key-Related APIs snippet in the Key Management guide presents
editor.getElementByKey(key)as a way to "Get node by key", and declaresconst nodetwice in the same block:getElementByKeyreturnsHTMLElement | null— the reconciled DOM element forthat key, not the
LexicalNode— and the duplicateconst nodewould not run.The following lines then call
node.getLatest()/node.getWritable(), whichare node methods, so as written they are applied to a DOM element.
This separates the two lookups and gives each its own name and comment.
Test plan
Documentation-only change (markdown is excluded from prettier via
.prettierignore), so the check is that each documented call is described bywhat it returns.
Before
The element lookup is labelled as a node lookup, and
const nodeis redeclared.After
nodenow comes from$getNodeByKey(packages/lexical/src/LexicalUtils.ts:681),so the
node.getLatest()/node.getWritable()lines that follow apply to aLexicalNode.