Skip to content

[lexical-code] Breaking change: drop the deprecated prism re-exports and the @lexical/code-prism dependency - #9141

Merged
etrepum merged 1 commit into
meta:mainfrom
etrepum:claude/gallant-hamilton-41dla2
Sep 9, 2026
Merged

etrepum merged 1 commit into
meta:mainfrom
etrepum:claude/gallant-hamilton-41dla2

Conversation

@etrepum

@etrepum etrepum commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

Description

@lexical/code depended on @lexical/code-prism purely to forward a set of @deprecated compatibility aliases (registerCodeHighlighting, PrismTokenizer, getCodeLanguages, getCodeLanguageOptions, getCodeThemeOptions, getLanguageFriendlyName, normalizeCodeLang, normalizeCodeLanguage, CODE_LANGUAGE_MAP,
CODE_LANGUAGE_FRIENDLY_NAME_MAP). Because @lexical/code-prism registers its grammars on the global Prism object at import time, that forwarding pulled all of prismjs into any bundle that imported @lexical/code for CodeNode alone, and @lexical/code had to be declared "sideEffects": true.

This removes those re-exports along with the @lexical/code-prism dependency, so @lexical/code is now a side-effect-free re-export of @lexical/code-core and prism highlighting lives only in @lexical/code-prism. The same symbols are still exported from @lexical/code-prism, which is where the deprecation notices pointed; normalizeCodeLang is normalizeCodeLanguage there.

Nothing under examples/ or dev-examples/ imported the removed symbols — they use @lexical/code-shiki or @lexical/code-core. The playground already declares @lexical/code-prism directly. The one consumer was the lexical-esm-astro-react integration fixture, which used them deliberately ("TODO: Using deprecated re-exports ... this can be refactored after that release"); it now imports them from @lexical/code-prism and declares that package, so it keeps exercising the same prismjs ESM bundling path.

Test plan

Bundling import {CodeNode} from '@lexical/code' with esbuild (--bundle --format=esm --conditions=source) before and after:

Before

bytes: 776411 | mentions Prism: true | prismjs in tree: true

After

bytes: 556652 | mentions Prism: false | prismjs in tree: false

packages/lexical-code/dist/LexicalCode.js and LexicalCode.dev.js after pnpm run build contain zero occurrences of prism (case-insensitive).

pnpm run test-unit:

 Test Files  324 passed (324)
      Tests  7278 passed | 1 skipped (7279)

pnpm run ci-check (tsc, tsc-scripts, tsc-extension, tsc-website, flow, prettier, lint) passes with no errors, as does pnpm run build-types.

The Playwright integration run for the lexical-esm-astro-react fixture was not exercised here: it runs against packed tarballs produced by prepare-release, which this environment does not build.

…and the @lexical/code-prism dependency

## Description

`@lexical/code` depended on `@lexical/code-prism` purely to forward a set of
`@deprecated` compatibility aliases (`registerCodeHighlighting`,
`PrismTokenizer`, `getCodeLanguages`, `getCodeLanguageOptions`,
`getCodeThemeOptions`, `getLanguageFriendlyName`, `normalizeCodeLang`,
`normalizeCodeLanguage`, `CODE_LANGUAGE_MAP`,
`CODE_LANGUAGE_FRIENDLY_NAME_MAP`). Because `@lexical/code-prism` registers its
grammars on the global `Prism` object at import time, that forwarding pulled all
of prismjs into any bundle that imported `@lexical/code` for `CodeNode` alone,
and `@lexical/code` had to be declared `"sideEffects": true`.

This removes those re-exports along with the `@lexical/code-prism` dependency, so
`@lexical/code` is now a side-effect-free re-export of `@lexical/code-core` and
prism highlighting lives only in `@lexical/code-prism`. The same symbols are
still exported from `@lexical/code-prism`, which is where the deprecation notices
pointed; `normalizeCodeLang` is `normalizeCodeLanguage` there.

Nothing under `examples/` or `dev-examples/` imported the removed symbols — they
use `@lexical/code-shiki` or `@lexical/code-core`. The playground already
declares `@lexical/code-prism` directly. The one consumer was the
`lexical-esm-astro-react` integration fixture, which used them deliberately
("TODO: Using deprecated re-exports ... this can be refactored after that
release"); it now imports them from `@lexical/code-prism` and declares that
package, so it keeps exercising the same prismjs ESM bundling path.

## Test plan

Bundling `import {CodeNode} from '@lexical/code'` with esbuild (`--bundle
--format=esm --conditions=source`) before and after:

### Before

```
bytes: 776411 | mentions Prism: true | prismjs in tree: true
```

### After

```
bytes: 556652 | mentions Prism: false | prismjs in tree: false
```

`packages/lexical-code/dist/LexicalCode.js` and `LexicalCode.dev.js` after
`pnpm run build` contain zero occurrences of `prism` (case-insensitive).

`pnpm run test-unit`:

```
 Test Files  324 passed (324)
      Tests  7278 passed | 1 skipped (7279)
```

`pnpm run ci-check` (tsc, tsc-scripts, tsc-extension, tsc-website, flow,
prettier, lint) passes with no errors, as does `pnpm run build-types`.

The Playwright integration run for the `lexical-esm-astro-react` fixture was not
exercised here: it runs against packed tarballs produced by `prepare-release`,
which this environment does not build.

Co-Authored-By: Claude Opus 5 <[email protected]>
@vercel

vercel Bot commented Sep 9, 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 9, 2026 8:45pm UTC
lexical-playground Ready Ready Preview Sep 9, 2026 8:45pm 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 9, 2026
@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label Sep 9, 2026
@etrepum
etrepum marked this pull request as ready for review September 9, 2026 20:44
@etrepum
etrepum added this pull request to the merge queue Sep 9, 2026
Merged via the queue into meta:main with commit 7e3f5f5 Sep 9, 2026
50 checks passed
@etrepum etrepum mentioned this pull request Sep 17, 2026
AlessioGr added a commit to payloadcms/payload that referenced this pull request Sep 30, 2026
…18397)

_Written with AI_

Upgrades `lexical` and every installed `@lexical/*` package from
`0.50.0` to `0.52.0` for Payload 4.x (`main`), and pinned `tsx`
dependencies from `4.22.4` to `4.23.15`. Removes the native-loader
workaround no longer needed with the new tsx version.

Also fixes duplicate image uploads triggered by repeated node transforms
in Lexical 0.52. CI fixes update the keyboard-navigation expectation and
correct an existing auth-test parameter error that blocked integration
tests.

Fixes #17757

3.x counterpart: #18398.

## Why this fixes the CLI failure

With Payload 3.90.1 on Node 22.22.0, importing a config that included
`lexicalEditor()` could leave CLI startup pending before the config or
target script was evaluated. The process then exited 0 with no output
and left a pending PostgreSQL migration unapplied. Previously, Payload
started the CLI with `void start()`, and an unresolved promise alone
does not keep Node's event loop alive.

Lexical 0.50's Node entry points select their build with top-level
`await import(...)`, which is probably what caused it. Lexical has
shipped ESM-only packages since **0.51**, using static imports instead
of those asynchronous Node wrappers. Upgrading to 0.52 fixes this issue.

Also removes the `module.registerHooks = undefined` workaround for
#16949. tsx 4.23.15 [excludes bare built-ins from namespace
inheritance](privatenumber/tsx@38e1588),
following its [Node 24 `tsImport` bridge
fix](privatenumber/tsx@6e5236b).

## CLI exit codes

CLI startup is now awaited at the top level in all three loader paths:
tsx, SWC, and disabled transpilation. If an import never settles and
Node runs out of work, Node reports an unsettled top-level await and
exits 13. Successful commands still exit 0, and command-specific failure
codes are preserved.

## Breaking changes

Rich-text data keeps its existing format. No database migration is
needed. Payload's built-in features have been updated, but your own
TypeScript code or custom features may need changes:

- **Generic types:** `SerializedEditorState<T>`,
`SerializedElementNode<T>`, and `SerializedRootNode<T>` no longer accept
`<T>`. Remove it if the base node type is enough, or use Payload's
`TypedEditorState<T>` for documents with your own node types. Without
`<T>`, children are still `SerializedLexicalNode[]`.
- **Export types:** `ReturnType<Node['exportJSON']>` can now make fields
such as `version` and `url` optional. Use the node's explicit serialized
type, such as `SerializedLinkNode`, when you need the full format.
Normal `node.exportJSON()` calls still return full JSON.
- **Selection listeners:** `SELECTION_CHANGE_COMMAND` now fires before
the DOM is updated. If your custom listener reads the DOM, defer that
work with `$onUpdate(() => editor.read('latest', callback))`.
- **Saved node references:** If you keep a node reference across an
editor update, call `node.getLatest().exportJSON()` to export its
current values.

The type changes also affect imports through
`@payloadcms/richtext-lexical/lexical` and its subpaths. Payload's
`TypedEditorState<T>` and its own serialized node types keep their
generic APIs for this upgrade.

Keep importing Lexical through Payload's re-exports; do not install a
separate Lexical version. See the [custom feature
documentation](https://payloadcms.com/docs/rich-text/custom-features).
The table below also lists removed APIs that may affect custom features.
`LexicalComposer` is deprecated but still available.

## Breaking changes and Payload migrations

Reviewed
[0.51.0](https://github.com/facebook/lexical/releases/tag/v0.51.0) and
[0.52.0](https://github.com/facebook/lexical/releases/tag/v0.52.0),
including the serialization declarations. **Yes** means Payload code
needed adaptation; **No** means no Payload migration was required.

| Release | Breaking change | Required migration in Payload | Changes
made |
| ------- | --------------- | ----------------------------- |
------------ |
| 0.51 | [npm packages are ESM
only](meta/lexical#9127); older CommonJS
consumers must use dynamic imports. | No | Payload already uses ESM.
This removes the asynchronous Lexical wrapper involved in the CLI
reproducer. |
| 0.51 | [Serialization schemas and compact
export](meta/lexical#8602) add `exportJSON`
overloads and remove the `SerializedEditorState`,
`SerializedElementNode`, and `SerializedRootNode` generics. `ReturnType`
can now infer compact, partial JSON. | Yes | Infer the full-format
overload for node hooks, validation and population while preserving
custom nodes' literal `type` discriminants. Update `hasText` to the
non-generic editor-state type. |
| 0.51 | [`exportJSON` can serialize a retained instance without calling
`getLatest()`](meta/lexical#8602). | No |
Audited Payload's clipboard and Markdown call sites: they serialize
nodes obtained from the current selection/tree, without an intervening
mutation. Custom callers holding stale references should use
`node.getLatest().exportJSON()`. |
| 0.51 | [Deprecated Prism re-exports are removed from
`@lexical/code`](meta/lexical#9141). | No |
Payload does not consume the removed exports. |
| 0.52 | [`SELECTION_CHANGE_COMMAND` runs before DOM
reconciliation](meta/lexical#9219),
including node and table selections. | Yes | Defer link popup, inline
toolbar and decorator DOM work with `$onUpdate` and
`editor.read('latest', ...)`. Keep nested decorator updates with their
own editor. The table menu already defers DOM reads. |
| 0.52 | [Default HTML export honors `DOMRenderExtension` `$createDOM`
overrides](meta/lexical#9231). | No |
Payload does not configure these extension overrides; existing converter
tests pass. |
| 0.52 | [`LexicalNode.getCommonAncestor` is
removed](meta/lexical#9238). | No | No
Payload call sites. Custom consumers can use `$getCommonAncestor`,
accounting for its different handling of non-element nodes. |

React package entry points were compared against 0.50.0; no Payload
proxy exports need adding or removing.

## Previous Lexical upgrades

- [#18149](#18149) — 0.48.0 →
0.50.0
- [#17554](#17554) — 0.45.0 →
0.48.0
- [#17064](#17064) — 0.41.0 →
0.45.0

This branch was successfully deployed

2 active deployments
Preview – lexical — ca23e19d Deployed Sep 9, 2026 by vercel[bot]
Preview – lexical-playground — ca23e19d Deployed Sep 9, 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. extended-tests Run extended e2e tests on a PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants