Repository navigation
[lexical-website] Documentation Update: fix the broken snippets in the extensions migration guide - #9211
Merged
etrepum merged 1 commit intoSep 23, 2026
Conversation
…e extensions migration guide
## Description
Several snippets in `extensions/migration.mdx` cannot be run as written:
1. **Syntax error in the all-in import list** — `configExtension` has no
trailing comma before `defineExtension`.
2. **The React "After" snippet uses three symbols it never imports** —
`defineExtension`, `configExtension` and `ReactExtension`.
3. **A JSX comment sits between `return (` and the element** it precedes,
which is not valid JSX — two adjacent expressions in a return. It becomes a
line comment, reordered so `// highlight-next-line` still targets the
component.
4. **The all-in `KeywordsExtension` calls `mergeRegister` without importing
it**, and passes a `getKeywordMatch` that the tab never defines (it exists
only as a component-local `useCallback` in the two earlier tabs). It is
added as a module-level function, matching the body those tabs wrap. The
same tab also imported `useCallback` and `useEffect` directly under a
highlighted comment saying "we don't even have a React dependency
anymore!" — neither was used, so the import is dropped.
5. **Identifier mismatch in the vanilla examples** — the first tab imports
`$prepopulatedRichText` and then calls `prepopulatedRichText`; the all-in
tab does the reverse, and calls `editor.setRootElement(editorRef)` with an
`editorRef` only declared in the earlier tabs.
Note on diff size: the syntax error in (1) meant prettier could not parse
those code blocks, so it had been leaving them unformatted. With it fixed they
parse, and `prettier --write` reformats them to project style (single quotes,
no bracket spacing, wrapped JSX attributes). That reformat is included here —
without it the file fails `pnpm run prettier`.
## Test plan
`.mdx` is *not* in `.prettierignore` (only `**/*.md` is), so this file is
formatter-checked; the checks below are prettier plus the identifiers.
### Before
```
$ sed -n '486,492p' packages/lexical-website/docs/extensions/migration.mdx
import {
$create,
TextNode,
configExtension
defineExtension,
safeCast,
} from "lexical";
$ node --input-type=module -e 'import {a, b c, d} from "x";'
SyntaxError: Unexpected identifier 'c'
$ grep -n "mergeRegister\|getKeywordMatch" packages/lexical-website/docs/extensions/migration.mdx
...
559: return mergeRegister(
562: getKeywordMatch,
$ grep -n "prepopulatedRichText\|editorRef" packages/lexical-website/docs/extensions/migration.mdx
25:import $prepopulatedRichText from './$prepopulatedRichText';
27:const editorRef = document.getElementById('lexical-editor');
53:editor.update(prepopulatedRichText, {tag: 'history-merge'});
103:import prepopulatedRichText from './prepopulatedRichText';
108: $initialEditorState: $prepopulatedRichText,
121:editor.setRootElement(editorRef);
```
`prettier --check` passes at this commit only because the unparseable block is
skipped.
### After
```
$ npx prettier --check packages/lexical-website/docs/extensions/migration.mdx
Checking formatting...
All matched files use Prettier code style!
$ grep -n "configExtension,$" packages/lexical-website/docs/extensions/migration.mdx
491: configExtension,
$ grep -n "function getKeywordMatch" packages/lexical-website/docs/extensions/migration.mdx
548:function getKeywordMatch(text: string) {
$ grep -n "mergeRegister} from '@lexical/utils'" packages/lexical-website/docs/extensions/migration.mdx
22:import {mergeRegister} from '@lexical/utils';
63:import {mergeRegister} from '@lexical/utils';
496:import {mergeRegister} from '@lexical/utils';
$ grep -n "useCallback, useEffect" packages/lexical-website/docs/extensions/migration.mdx
281:import {useCallback, useEffect} from 'react';
382:import {useCallback, useEffect} from 'react';
$ grep -n "prepopulatedRichText\|editorRef" packages/lexical-website/docs/extensions/migration.mdx
25:import $prepopulatedRichText from './$prepopulatedRichText';
27:const editorRef = document.getElementById('lexical-editor');
44:editor.setRootElement(editorRef);
53:editor.update($prepopulatedRichText, {tag: 'history-merge'});
66:import $prepopulatedRichText from './$prepopulatedRichText';
68:const editorRef = document.getElementById('lexical-editor');
84:editor.setRootElement(editorRef);
93:editor.update($prepopulatedRichText, {tag: 'history-merge'});
103:import $prepopulatedRichText from './$prepopulatedRichText';
105:const editorRef = document.getElementById('lexical-editor');
110: $initialEditorState: $prepopulatedRichText,
123:editor.setRootElement(editorRef);
```
The React import now appears only in the two tabs that use hooks, and every
identifier each tab references is declared or imported within that tab.
potatowagon
requested review from
acywatson,
etrepum,
fantactuka,
ivailop7 and
zurfyx
as code owners
September 23, 2026 17:46
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
etrepum
approved these changes
Sep 23, 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
Several snippets in
extensions/migration.mdxcannot be run as written:configExtensionhas notrailing comma before
defineExtension.defineExtension,configExtensionandReactExtension.return (and the element it precedes,which is not valid JSX — two adjacent expressions in a return. It becomes a
line comment, reordered so
// highlight-next-linestill targets thecomponent.
KeywordsExtensioncallsmergeRegisterwithout importingit, and passes a
getKeywordMatchthat the tab never defines (it existsonly as a component-local
useCallbackin the two earlier tabs). It isadded as a module-level function, matching the body those tabs wrap. The
same tab also imported
useCallbackanduseEffectdirectly under ahighlighted comment saying "we don't even have a React dependency
anymore!" — neither was used, so the import is dropped.
$prepopulatedRichTextand then callsprepopulatedRichText; the all-intab does the reverse, and calls
editor.setRootElement(editorRef)with aneditorRefonly declared in the earlier tabs.Note on diff size: the syntax error in (1) meant prettier could not parse
those code blocks, so it had been leaving them unformatted. With it fixed they
parse, and
prettier --writereformats them to project style (single quotes,no bracket spacing, wrapped JSX attributes). That reformat is included here —
without it the file fails
pnpm run prettier.Test plan
.mdxis not in.prettierignore(only**/*.mdis), so this file isformatter-checked; the checks below are prettier plus the identifiers.
Before
prettier --checkpasses at this commit only because the unparseable block isskipped.
After
The React import now appears only in the two tabs that use hooks, and every
identifier each tab references is declared or imported within that tab.