Skip to content

[lexical-website] Documentation Update: fix the broken snippets in the extensions migration guide - #9211

Merged
etrepum merged 1 commit into
meta:mainfrom
potatowagon:docs-extensions-migration-snippets
Sep 23, 2026
Merged

etrepum merged 1 commit into
meta:mainfrom
potatowagon:docs-extensions-migration-snippets

Conversation

@potatowagon

Copy link
Copy Markdown
Contributor

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.

…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.
@vercel

vercel Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
lexical Ready Ready Preview Sep 23, 2026 5:48pm UTC
lexical-playground Ready Ready Preview Sep 23, 2026 5:48pm UTC

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 Sep 23, 2026
@etrepum
etrepum added this pull request to the merge queue Sep 23, 2026
Merged via the queue into meta:main with commit 599830a Sep 23, 2026
42 checks passed
@etrepum etrepum mentioned this pull request Sep 28, 2026

This branch was successfully deployed

2 active deployments
Preview – lexical — e63eaab8 Deployed Sep 23, 2026 by vercel[bot]
Preview – lexical-playground — e63eaab8 Deployed Sep 23, 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.

2 participants