Repository navigation
fix(richtext-lexical): upgrade lexical-markdown, fix errors, deduplicate code, fix exports - #13708
Closed
GermanJablo wants to merge 19 commits into
Closed
GermanJablo wants to merge 19 commits into
GermanJablo wants to merge 19 commits into
Conversation
GermanJablo
commented
Sep 8, 2025
| * `export` and `replace` methods of this transformer, as Payload cannot | ||
| * infer the correct URL format on its own. | ||
| */ | ||
| export const PAYLOAD_LINK_TRANSFORMER: TextMatchTransformer = { |
Contributor
Author
There was a problem hiding this comment.
In another PR, we should decide whether and how to export it. In the meantime, I've renamed it to maintain consistency with the other Lexical transformers.
GermanJablo
commented
Sep 8, 2025
Comment on lines
+68
to
+73
| user: usersQuery.docs[0] | ||
| ? { | ||
| collection: 'users', | ||
| ...usersQuery.docs[0], | ||
| } | ||
| : null, |
Contributor
Author
There was a problem hiding this comment.
Unrelated to the PR. This appeared after merge from main because apparently someone used --no-verify. We should run prettier in CI.
Contributor
📦 esbuild Bundle Analysis for payloadThis analysis was generated by esbuild-bundle-analyzer. 🤖
Largest pathsThese visualization shows top 20 largest paths in the bundle.Meta file: packages/next/meta_index.json, Out file: esbuild/index.js
Meta file: packages/payload/meta_index.json, Out file: esbuild/index.js
Meta file: packages/payload/meta_shared.json, Out file: esbuild/exports/shared.js
Meta file: packages/richtext-lexical/meta_client.json, Out file: esbuild/exports/client_optimized/index.js
Meta file: packages/ui/meta_client.json, Out file: esbuild/exports/client_optimized/index.js
Meta file: packages/ui/meta_shared.json, Out file: esbuild/exports/shared_optimized/index.js
DetailsNext to the size is how much the size has increased or decreased compared with the base branch of this PR.
|
1 task
GermanJablo
added a commit
that referenced
this pull request
Jun 28, 2026
…d upgrade to lexical 0.45 (#17064) ## Summary Payload vendored a full copy of `@lexical/markdown` because, before lexical `0.42`, the published package transitively pulled in `@lexical/code` + `prismjs`, which broke type generation. Lexical `0.42` switched to `@lexical/code-core` (no prism), so the fork is no longer needed. - **Upgrade to lexical `0.45.0`** (all `@lexical/*` from `0.41.0`), add `@lexical/[email protected]` as a dependency, and delete the vendored copy. - **Make `@payloadcms/richtext-lexical/lexical/markdown` a pure passthrough** (`export * from '@lexical/markdown'`), consistent with every other `@lexical/*` proxy. Payload's `normalizeMarkdown` preprocessing moves into an internal `$convertFromMarkdownString` helper, so the public export behaves the same. - **Deduplicate transformers that never diverged from upstream** (text-format, quote, list) so they import directly from `@lexical/markdown`, and reduce the heading transformer to `{ ...HEADING, regExp }` so it tracks upstream. - **Prefix the intentional divergences with `PAYLOAD_`** (`PAYLOAD_HEADING`, `PAYLOAD_LINK`, `PAYLOAD_UPLOAD`, `PAYLOAD_HORIZONTAL_RULE`, `PAYLOAD_TABLE`); they handle Payload-specific nodes with no upstream equivalent. - **Add ESLint rule `payload/no-conflicting-lexical-markdown-imports`** that flags Lexical's `CODE` / `LINK` / `HEADING` transformers, the default transformer groups, and convert/register calls that omit an explicit transformer list, since these silently conflict with Payload's features. ## Related Supersedes #13708. ## Payload API Breaking Changes ### 1. `$convertFromMarkdownString` no longer merges adjacent lines by default If you call it directly, pass `shouldMergeAdjacentLines: true` (5th arg) to keep the old behavior: ```diff - $convertFromMarkdownString(markdown, transformers) + $convertFromMarkdownString(markdown, transformers, undefined, false, true) ``` ### 2. Markdown transformer defaults now match upstream lexical (not Payload's features) The vendored fork shipped a curated `TRANSFORMERS` set (no `CODE`, no `LINK`). Both `@payloadcms/richtext-lexical/lexical/markdown` (now a pure passthrough) and the default argument to `$convertFromMarkdownString` exported from `@payloadcms/richtext-lexical` now use lexical's `TRANSFORMERS`, which bundles `CODE`, `LINK`, and `HEADING` transformers that conflict with Payload's features. You are affected if you either: - imported a group (`TRANSFORMERS`, `ELEMENT_TRANSFORMERS`, ...) from `@payloadcms/richtext-lexical/lexical/markdown`, or - called `$convertFromMarkdownString(markdown)` from `@payloadcms/richtext-lexical` without passing a transformer list. Switch to the converters, which build the list from your editor's enabled features: ```diff - import { $convertFromMarkdownString, TRANSFORMERS } from '@payloadcms/richtext-lexical/lexical/markdown' - $convertFromMarkdownString(markdown, TRANSFORMERS) + import { convertMarkdownToLexical } from '@payloadcms/richtext-lexical' + convertMarkdownToLexical({ editorConfig, markdown }) ``` If you keep calling `$convertFromMarkdownString` directly, pass `editorConfig.features.markdownTransformers` as the second argument. Enable `payload/no-conflicting-lexical-markdown-imports` (included in `@payloadcms/eslint-config`) to catch imports and calls that rely on these mismatching defaults. ## Lexical Breaking Changes This PR also bumps every `@lexical/*` package from `0.41.0` to `0.45.0`. The releases below contain breaking changes. We recommend reading them if you use Lexical APIs directly (`@payloadcms/richtext-lexical/lexical/*`). None of them require action for typical Payload usage. - [v0.45.0](https://github.com/facebook/lexical/releases/tag/v0.45.0) - `registerRichText` / `registerPlainText` now strip empty inline elements (`NormalizeInlineElementsExtension`) and the triple-click selection normalization moved into `NormalizeTripleClickSelectionExtension`. Editors that bypass `registerRichText` / `registerPlainText` must register these extensions to keep the old behavior. - Backspace at the start of a non-empty block now preserves the current block's type instead of merging it into the previous block. - Markdown shortcuts (`*`, `_`, `~`) now fire on IME composition commit (fixes dropped shortcuts for Japanese / Korean / Chinese input). - **Whitespace-only markdown table cells now import as an empty paragraph** instead of a text node of padding spaces. No migration needed unless you assert on those padding spaces. - [v0.44.0](https://github.com/facebook/lexical/releases/tag/v0.44.0) - The "press Enter three times to exit a code block" logic moved from `CodeNode` into `CodeExtension`; using `CodeNode` without `CodeExtension` is deprecated (backwards-compatible shim with a dev-mode warning). - `@lexical/offset` `OffsetView` is deprecated; import `$createChildrenArray` from `lexical` instead. - [v0.43.0](https://github.com/facebook/lexical/releases/tag/v0.43.0) - `@lexical/react` nested editors use asynchronous parent editor delegation to restore pre-`0.42.0` behavior. - [v0.42.0](https://github.com/facebook/lexical/releases/tag/v0.42.0) - Prism highlighting was extracted from `@lexical/code` into `@lexical/code-prism`, with a prism-free `@lexical/code-core`. This is the change that lets Payload drop its vendored `@lexical/markdown` fork. - Markdown import was aligned with CommonMark (trailing-space flanking rules, backslash handling, tabs converted to `TabNode`). The whitespace-only table cell change noted above originates from these markdown import changes. - Editor listeners (`registerUpdateListener`, root/editable listeners) may now return an unregister callback that Lexical calls on teardown. Returning a non-function value (e.g. an accidental Promise) throws `unregister is not a function`; Payload's toolbar listener was updated accordingly. ## Previous Lexical Upgrades - [#15760](#15760) — 0.35.0 → 0.41.0 - [#13715](#13715) — 0.34.0 → 0.35.0 - [#13622](#13622) — 0.28.0 → 0.34.0 - [#11764](#11764) — 0.27.2 → 0.28.0 - [#11564](#11564) — 0.21.0 → 0.27.1 ## Pending / Blocked - [ ] Delete `normalizeMarkdown` and the internal `$convertFromMarkdownString` helper once [meta/lexical#8734](meta/lexical#8734) (nested code fence fix) merges and we upgrade to a release that includes it. Both carry a matching `TODO`. --------- Co-authored-by: German Jablonski <[email protected]>
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.
TODO:
@lexical/markdownfrom@lexical/codein the Lexical repository and/or find out why@lexical/codeis generating errors @AlessioGrnormalizaMarkdownto Lexical @GermanJabloFinally, the modules we're overriding will be renamed in v4, likely with a
PAYLOAD_prefix. These are:MULTILINE_ELEMENT_TRANSFORMERSTEXT_MATCH_TRANSFORMERSTRANSFORMERSLexical Breaking Changes:
The following Lexical releases describe breaking changes in the
@lexical/markdownpackage. We recommend reading them if you're using Lexical/markdown APIs directly (@payloadcms/richtext-lexical/lexical/markdown).v.0.30.0
v.0.29.0
#6660
Regarding the last one, we were importing
$convertFromMarkdownStringfrom both@payloadcms/richtext-lexicaland@payloadcms/richtext-lexical/lexical/markdown, with the only difference being the default value of the 5th parameter, (mergeAdjacentLines).The export from the first path,
@payloadcms/richtext-lexicalhas been marked as deprecated and will be removed in the next major release of Payload. Both imports now follow the change in the default value of the 5th parametermergeAdjacentLines.If you were importing
$convertFromMarkdownStringorconvertMarkdownToLexicalfrom the root path (@payloadcms/richtext-lexical) and you want to keep your Markdown output the same, you have two options:mergeAdjacentLines".$convertFromMarkdownStringto true:and set the
mergeAdjacentLinesparameter to true in ourconvertMarkdownToLexicalwrapper.import { convertMarkdownToLexical } from '@payloadcms/richtext-lexical' - convertMarkdownToLexical({ editorConfig, markdown }) + convertMarkdownToLexical({ editorConfig, markdown, mergeAdjacentLines: true })Description
Previously, instead of installing
@lexical/markdownlike the rest of the Lexical packages, we had copied its code directly into our repo.Because of this, we fell behind for almost a year, missing many upstream bug fixes and improvements.
This PR brings in those missing updates.
I carefully compared every module one by one. I only found these changes that we had made independently from Lexical’s development:
normalizeMarkdownbug fixesMULTILINE_ELEMENT_TRANSFORMERSis an empty array in our case, while it containsCODEin Lexical.TEXT_MATCH_TRANSFORMERScontainsPAYLOAD_LINK_TRANSFORMERin our case, while it cointainsLINK_TRANSFORMERin Lexical.TRANSFORMERSis an array that includesMULTILINE_ELEMENT_TRANSFORMERSandTEXT_MATCH_TRANSFORMERS, and therefore It is different.The
$convertFromMarkdownString5th parameter (shouldMergeAdjacentLines)falsefor backward compatibility shortly after that configuration option was introduced..mdxsource code.convertMarkdownToLexicalwrapper to accept that option as a parameter.For now, both our codebase and Lexical have several Markdown transformers that remain internal and are not exported.
To keep the scope of this PR manageable, they remain untouched.
In a follow-up PR, ideally in collaboration with the Lexical team, we should decide which transformers should be exported upstream, and which should stay customized in our code (likely only Link and Blocks).
Why you probably don't want
mergeAdjacentLinesmergeAdjacentLinesis a gray area within Markdown. In theory and according to the specification, it should be true. But in practice,falseis used for convenience in many places, such as GitHub comments.The reason we introduced that option and actually contributed it to Lexical is kind of funny in retrospect.
We were using Prettier in our documentation to keep the line widths of our
.mdxfiles reasonable, since it's horrible to have to scroll horizontally to read.However, Prettier now allows you to define a line width "just for code snippets." You may be wondering why you would want that. If so, you're probably like me, who recently learned that
Option+Ztogglesword wrapin VSCode. When it comes to Markdown, that's even better than using Prettier since it dynamically adapts to the viewport width.Conclusion: instead of enabling
mergeAdjacentLines, it is better to use prettier ONLY for code blocks, and VSCodeword wrapfor the rest.