Skip to content

fix(richtext-lexical): upgrade lexical-markdown, fix errors, deduplicate code, fix exports - #13708

Closed
GermanJablo wants to merge 19 commits into
mainfrom
fix/markdown-links
Closed

GermanJablo wants to merge 19 commits into
mainfrom
fix/markdown-links

Conversation

@GermanJablo

@GermanJablo GermanJablo commented Sep 5, 2025 •

Copy link
Copy Markdown
Contributor

TODO:

  •  Decouple @lexical/markdown from @lexical/code in the Lexical repository and/or find out why @lexical/code is generating errors @AlessioGr
  • porting our improved normalizaMarkdown to Lexical @GermanJablo

Finally, the modules we're overriding will be renamed in v4, likely with a PAYLOAD_ prefix. These are:

  • MULTILINE_ELEMENT_TRANSFORMERS
  • TEXT_MATCH_TRANSFORMERS
  • TRANSFORMERS

Lexical Breaking Changes:

The following Lexical releases describe breaking changes in the @lexical/markdown package. 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 $convertFromMarkdownString from both @payloadcms/richtext-lexical and @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-lexical has 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 parameter mergeAdjacentLines.

If you were importing $convertFromMarkdownString or convertMarkdownToLexical from the root path (@payloadcms/richtext-lexical) and you want to keep your Markdown output the same, you have two options:

  1. Make sure the input isn’t using manual line breaks to control line width (likely added by Prettier). This is the recommended option; for more info read the section below "Why you probably don't want mergeAdjacentLines".
  2. Explicitly set the 5th parameter of $convertFromMarkdownString to true:
- import { $convertFromMarkdownString } from '@payloadcms/richtext-lexical'
+ import { $convertFromMarkdownString } from '@payloadcms/richtext-lexical/lexical/markdown'

- $convertFromMarkdownString('string', TRANSFORMERS)
+ $convertFromMarkdownString('string', TRANSFORMERS, undefined, false, true)

and set the mergeAdjacentLines parameter to true in our convertMarkdownToLexical wrapper.

import { convertMarkdownToLexical } from '@payloadcms/richtext-lexical'

- convertMarkdownToLexical({ editorConfig, markdown })
+ convertMarkdownToLexical({ editorConfig, markdown, mergeAdjacentLines: true })

Description

Previously, instead of installing @lexical/markdown like 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:

  1. normalizeMarkdown bug fixes

    • This is the only module we still keep duplicated.
    • In this PR, we continue exporting our patched version, which overwrites Lexical’s default.
    • The plan: submit our fixes back to Lexical, wait for them to be released, and then remove our copy.
  2. MULTILINE_ELEMENT_TRANSFORMERS is an empty array in our case, while it contains CODE in Lexical.

  3. TEXT_MATCH_TRANSFORMERS contains PAYLOAD_LINK_TRANSFORMER in our case, while it cointains LINK_TRANSFORMER in Lexical.

  4. TRANSFORMERS is an array that includes MULTILINE_ELEMENT_TRANSFORMERS and TEXT_MATCH_TRANSFORMERS, and therefore It is different.

  5. The $convertFromMarkdownString 5th parameter (shouldMergeAdjacentLines)

    • Lexical changed its default value to false for backward compatibility shortly after that configuration option was introduced.
    • We had been mistakenly exporting this function twice: once from the root package and once via the Lexical proxy.
    • In this PR, we remove our outdated duplicate.
    • This can probably affect our website, in which case we should remove the line break from the .mdx source code.
    • I updated our convertMarkdownToLexical wrapper 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 mergeAdjacentLines

mergeAdjacentLines is a gray area within Markdown. In theory and according to the specification, it should be true. But in practice, false is 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 .mdx files 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+Z toggles word wrap in 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 VSCode word wrap for the rest.

@GermanJablo
GermanJablo marked this pull request as ready for review September 8, 2025 15:14
* `export` and `replace` methods of this transformer, as Payload cannot
* infer the correct URL format on its own.
*/
export const PAYLOAD_LINK_TRANSFORMER: TextMatchTransformer = {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +68 to +73
user: usersQuery.docs[0]
? {
collection: 'users',
...usersQuery.docs[0],
}
: null,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to the PR. This appeared after merge from main because apparently someone used --no-verify. We should run prettier in CI.

@github-actions

github-actions Bot commented Sep 8, 2025 •

Copy link
Copy Markdown
Contributor

📦 esbuild Bundle Analysis for payload

This analysis was generated by esbuild-bundle-analyzer. 🤖

Meta File Out File Size (raw) Note
packages/next/meta_index.json esbuild/index.js 754.30 KB ✅ No change
packages/payload/meta_index.json esbuild/index.js 1.21 MB ✅ No change
packages/payload/meta_shared.json esbuild/exports/shared.js 161.04 KB ✅ No change
packages/richtext-lexical/meta_client.json esbuild/exports/client_optimized/index.js 238.08 KB ✅ -20.79 KB (-8.0%)
packages/ui/meta_client.json esbuild/exports/client_optimized/index.js 1.15 MB ✅ No change
packages/ui/meta_shared.json esbuild/exports/shared_optimized/index.js 14.20 KB ✅ No change
Largest paths These visualization shows top 20 largest paths in the bundle.

Meta file: packages/next/meta_index.json, Out file: esbuild/index.js

Path Size
../../node_modules ${{\color{Goldenrod}{ ████████████████████ }}}$ 80.3%, 601.88 KB
dist/views/Version ${{\color{Goldenrod}{ █▋ }}}$ 6.7%, 50.06 KB
dist/views/Document ${{\color{Goldenrod}{ ▌ }}}$ 2.0%, 14.91 KB
dist/views/List ${{\color{Goldenrod}{ ▎ }}}$ 1.3%, 9.43 KB
dist/views/Root ${{\color{Goldenrod}{ ▏ }}}$ 0.9%, 7.08 KB
dist/views/Versions ${{\color{Goldenrod}{ ▏ }}}$ 0.8%, 6.30 KB
dist/views/API ${{\color{Goldenrod}{ ▏ }}}$ 0.8%, 5.98 KB
dist/views/Account ${{\color{Goldenrod}{ ▏ }}}$ 0.7%, 5.32 KB
dist/elements/Nav ${{\color{Goldenrod}{ ▏ }}}$ 0.6%, 4.84 KB
dist/elements/DocumentHeader ${{\color{Goldenrod}{ ▏ }}}$ 0.6%, 4.81 KB
dist/views/Login ${{\color{Goldenrod}{ ▏ }}}$ 0.6%, 4.39 KB
dist/views/Dashboard ${{\color{Goldenrod}{ ▏ }}}$ 0.5%, 3.68 KB
dist/views/ForgotPassword ${{\color{Goldenrod}{ }}}$ 0.4%, 3.09 KB
dist/layouts/Root ${{\color{Goldenrod}{ }}}$ 0.4%, 3.09 KB
dist/utilities/initPage ${{\color{Goldenrod}{ }}}$ 0.4%, 3.06 KB
dist/templates/Default ${{\color{Goldenrod}{ }}}$ 0.4%, 2.83 KB
dist/views/CreateFirstUser ${{\color{Goldenrod}{ }}}$ 0.4%, 2.74 KB
dist/views/BrowseByFolder ${{\color{Goldenrod}{ }}}$ 0.3%, 2.60 KB
dist/views/CollectionFolders ${{\color{Goldenrod}{ }}}$ 0.3%, 2.46 KB
dist/views/ResetPassword ${{\color{Goldenrod}{ }}}$ 0.3%, 2.41 KB
(other) ${{\color{Goldenrod}{ ████▉ }}}$ 19.7%, 147.74 KB

Meta file: packages/payload/meta_index.json, Out file: esbuild/index.js

Path Size
../../node_modules ${{\color{Goldenrod}{ █████████████████▍ }}}$ 69.7%, 841.07 KB
dist/fields/hooks ${{\color{Goldenrod}{ ▊ }}}$ 3.3%, 40.21 KB
dist/collections/operations ${{\color{Goldenrod}{ ▊ }}}$ 3.0%, 36.05 KB
dist/auth/operations ${{\color{Goldenrod}{ ▎ }}}$ 1.3%, 15.30 KB
dist/queues/operations ${{\color{Goldenrod}{ ▎ }}}$ 1.0%, 12.00 KB
dist/utilities/configToJSONSchema.js ${{\color{Goldenrod}{ ▎ }}}$ 1.0%, 11.54 KB
dist/globals/operations ${{\color{Goldenrod}{ ▏ }}}$ 0.9%, 11.15 KB
dist/fields/config ${{\color{Goldenrod}{ ▏ }}}$ 0.9%, 10.82 KB
dist/fields/validations.js ${{\color{Goldenrod}{ ▏ }}}$ 0.8%, 9.38 KB
dist/bin/generateImportMap ${{\color{Goldenrod}{ ▏ }}}$ 0.7%, 8.27 KB
dist/database/migrations ${{\color{Goldenrod}{ ▏ }}}$ 0.6%, 7.79 KB
dist/collections/config ${{\color{Goldenrod}{ ▏ }}}$ 0.6%, 7.79 KB
dist/uploads/fetchAPI-multipart ${{\color{Goldenrod}{ ▏ }}}$ 0.6%, 7.74 KB
dist/index.js ${{\color{Goldenrod}{ ▏ }}}$ 0.6%, 7.37 KB
dist/collections/endpoints ${{\color{Goldenrod}{ ▏ }}}$ 0.6%, 7.29 KB
dist/config/orderable ${{\color{Goldenrod}{ ▏ }}}$ 0.5%, 6.25 KB
dist/auth/strategies ${{\color{Goldenrod}{ ▏ }}}$ 0.5%, 5.50 KB
dist/config/sanitize.js ${{\color{Goldenrod}{ ▏ }}}$ 0.5%, 5.44 KB
dist/auth/endpoints ${{\color{Goldenrod}{ }}}$ 0.4%, 5.41 KB
dist/utilities/telemetry ${{\color{Goldenrod}{ }}}$ 0.4%, 5.31 KB
(other) ${{\color{Goldenrod}{ ███████▌ }}}$ 30.3%, 365.98 KB

Meta file: packages/payload/meta_shared.json, Out file: esbuild/exports/shared.js

Path Size
../../node_modules ${{\color{Goldenrod}{ ████████████████████ }}}$ 80.4%, 126.93 KB
dist/fields/validations.js ${{\color{Goldenrod}{ █▍ }}}$ 5.9%, 9.38 KB
dist/fields/baseFields ${{\color{Goldenrod}{ ▍ }}}$ 1.8%, 2.79 KB
dist/utilities/deepCopyObject.js ${{\color{Goldenrod}{ ▍ }}}$ 1.6%, 2.48 KB
dist/auth/cookies.js ${{\color{Goldenrod}{ ▎ }}}$ 1.0%, 1.55 KB
dist/utilities/flattenTopLevelFields.js ${{\color{Goldenrod}{ ▏ }}}$ 0.9%, 1.42 KB
dist/fields/config ${{\color{Goldenrod}{ ▏ }}}$ 0.8%, 1.28 KB
dist/utilities/flattenAllFields.js ${{\color{Goldenrod}{ ▏ }}}$ 0.6%, 943 B
dist/folders/utils ${{\color{Goldenrod}{ ▏ }}}$ 0.6%, 916 B
dist/utilities/unflatten.js ${{\color{Goldenrod}{ ▏ }}}$ 0.5%, 779 B
dist/utilities/sanitizeUserDataForEmail.js ${{\color{Goldenrod}{ ▏ }}}$ 0.5%, 713 B
dist/collections/config ${{\color{Goldenrod}{ }}}$ 0.4%, 570 B
dist/bin/generateImportMap ${{\color{Goldenrod}{ }}}$ 0.4%, 559 B
dist/auth/sessions.js ${{\color{Goldenrod}{ }}}$ 0.3%, 545 B
dist/utilities/getSafeRedirect.js ${{\color{Goldenrod}{ }}}$ 0.3%, 423 B
dist/utilities/deepMerge.js ${{\color{Goldenrod}{ }}}$ 0.3%, 413 B
dist/utilities/getFieldPermissions.js ${{\color{Goldenrod}{ }}}$ 0.2%, 391 B
dist/utilities/formatLabels.js ${{\color{Goldenrod}{ }}}$ 0.2%, 380 B
dist/utilities/transformColumnPreferences.js ${{\color{Goldenrod}{ }}}$ 0.2%, 348 B
dist/utilities/mergeListSearchAndWhere.js ${{\color{Goldenrod}{ }}}$ 0.2%, 344 B
(other) ${{\color{Goldenrod}{ ████▉ }}}$ 19.6%, 30.91 KB

Meta file: packages/richtext-lexical/meta_client.json, Out file: esbuild/exports/client_optimized/index.js

Path Size
dist/lexical/plugins ${{\color{Goldenrod}{ ███▎ }}}$ 13.2%, 31.01 KB
dist/features/experimental_table ${{\color{Goldenrod}{ ██▌ }}}$ 10.1%, 23.75 KB
dist/lexical/ui ${{\color{Goldenrod}{ ██▌ }}}$ 10.0%, 23.47 KB
dist/features/blocks ${{\color{Goldenrod}{ ██▍ }}}$ 9.5%, 22.42 KB
dist/features/link ${{\color{Goldenrod}{ █▉ }}}$ 7.6%, 17.96 KB
dist/features/toolbars ${{\color{Goldenrod}{ █▉ }}}$ 7.5%, 17.68 KB
dist/features/textState ${{\color{Goldenrod}{ █▏ }}}$ 4.7%, 11.02 KB
dist/features/upload ${{\color{Goldenrod}{ █ }}}$ 4.1%, 9.60 KB
dist/features/relationship ${{\color{Goldenrod}{ █ }}}$ 4.0%, 9.41 KB
dist/lexical/utils ${{\color{Goldenrod}{ ▊ }}}$ 3.4%, 8.08 KB
dist/features/debug ${{\color{Goldenrod}{ ▊ }}}$ 3.1%, 7.39 KB
dist/features/converters ${{\color{Goldenrod}{ ▊ }}}$ 3.0%, 7.04 KB
dist/utilities/fieldsDrawer ${{\color{Goldenrod}{ ▊ }}}$ 3.0%, 7.01 KB
dist/lexical/config ${{\color{Goldenrod}{ ▌ }}}$ 2.2%, 5.10 KB
dist/lexical/theme ${{\color{Goldenrod}{ ▍ }}}$ 1.7%, 4.01 KB
dist/features/lists ${{\color{Goldenrod}{ ▍ }}}$ 1.5%, 3.59 KB
dist/lexical/LexicalEditor.js ${{\color{Goldenrod}{ ▍ }}}$ 1.5%, 3.46 KB
dist/features/format ${{\color{Goldenrod}{ ▎ }}}$ 1.4%, 3.28 KB
dist/features/indent ${{\color{Goldenrod}{ ▎ }}}$ 1.1%, 2.50 KB
dist/features/horizontalRule ${{\color{Goldenrod}{ ▎ }}}$ 1.0%, 2.39 KB
(other) ${{\color{Goldenrod}{ █████████████████████▋ }}}$ 86.8%, 204.04 KB

Meta file: packages/ui/meta_client.json, Out file: esbuild/exports/client_optimized/index.js

Path Size
../../node_modules ${{\color{Goldenrod}{ ████████████▌ }}}$ 50.2%, 572.93 KB
dist/elements/FolderView ${{\color{Goldenrod}{ ▋ }}}$ 2.7%, 30.37 KB
dist/elements/BulkUpload ${{\color{Goldenrod}{ ▌ }}}$ 2.2%, 24.57 KB
dist/elements/WhereBuilder ${{\color{Goldenrod}{ ▎ }}}$ 1.4%, 16.26 KB
dist/fields/Relationship ${{\color{Goldenrod}{ ▎ }}}$ 1.4%, 16.11 KB
dist/views/Edit ${{\color{Goldenrod}{ ▎ }}}$ 1.4%, 15.43 KB
dist/elements/Table ${{\color{Goldenrod}{ ▎ }}}$ 1.3%, 15.26 KB
dist/forms/Form ${{\color{Goldenrod}{ ▎ }}}$ 1.3%, 14.77 KB
dist/fields/Blocks ${{\color{Goldenrod}{ ▎ }}}$ 1.1%, 12.43 KB
dist/fields/Upload ${{\color{Goldenrod}{ ▎ }}}$ 1.0%, 11.94 KB
dist/fields/Array ${{\color{Goldenrod}{ ▏ }}}$ 0.8%, 9.30 KB
dist/elements/QueryPresets ${{\color{Goldenrod}{ ▏ }}}$ 0.8%, 9.08 KB
dist/elements/PublishButton ${{\color{Goldenrod}{ ▏ }}}$ 0.8%, 8.72 KB
dist/providers/Folders ${{\color{Goldenrod}{ ▏ }}}$ 0.7%, 8.38 KB
dist/elements/LivePreview ${{\color{Goldenrod}{ ▏ }}}$ 0.7%, 8.26 KB
dist/elements/ListHeader ${{\color{Goldenrod}{ ▏ }}}$ 0.7%, 7.98 KB
dist/views/CollectionFolder ${{\color{Goldenrod}{ ▏ }}}$ 0.7%, 7.97 KB
dist/elements/HTMLDiff ${{\color{Goldenrod}{ ▏ }}}$ 0.7%, 7.81 KB
dist/views/List ${{\color{Goldenrod}{ ▏ }}}$ 0.6%, 7.18 KB
dist/elements/ReactSelect ${{\color{Goldenrod}{ ▏ }}}$ 0.6%, 6.91 KB
(other) ${{\color{Goldenrod}{ ████████████▍ }}}$ 49.8%, 567.96 KB

Meta file: packages/ui/meta_shared.json, Out file: esbuild/exports/shared_optimized/index.js

Path Size
dist/graphics/Logo ${{\color{Goldenrod}{ █████▋ }}}$ 22.9%, 3.12 KB
../../node_modules ${{\color{Goldenrod}{ ████▉ }}}$ 19.5%, 2.65 KB
dist/graphics/Icon ${{\color{Goldenrod}{ ██▊ }}}$ 11.2%, 1.52 KB
dist/utilities/formatDocTitle ${{\color{Goldenrod}{ ██▍ }}}$ 9.7%, 1.32 KB
dist/providers/TableColumns ${{\color{Goldenrod}{ █▌ }}}$ 6.3%, 862 B
dist/utilities/groupNavItems.js ${{\color{Goldenrod}{ █▌ }}}$ 6.0%, 814 B
dist/utilities/api.js ${{\color{Goldenrod}{ █▍ }}}$ 5.6%, 756 B
dist/elements/Translation ${{\color{Goldenrod}{ ▉ }}}$ 3.6%, 493 B
dist/elements/withMergedProps ${{\color{Goldenrod}{ ▋ }}}$ 2.5%, 339 B
dist/utilities/handleTakeOver.js ${{\color{Goldenrod}{ ▍ }}}$ 1.8%, 251 B
dist/elements/WithServerSideProps ${{\color{Goldenrod}{ ▍ }}}$ 1.7%, 232 B
dist/utilities/handleGoBack.js ${{\color{Goldenrod}{ ▎ }}}$ 1.2%, 168 B
dist/fields/mergeFieldStyles.js ${{\color{Goldenrod}{ ▎ }}}$ 1.2%, 159 B
dist/forms/Form ${{\color{Goldenrod}{ ▎ }}}$ 1.1%, 147 B
dist/utilities/abortAndIgnore.js ${{\color{Goldenrod}{ ▎ }}}$ 1.1%, 146 B
dist/utilities/hasSavePermission.js ${{\color{Goldenrod}{ ▎ }}}$ 1.0%, 136 B
dist/utilities/handleBackToDashboard.js ${{\color{Goldenrod}{ ▏ }}}$ 0.9%, 129 B
dist/utilities/findLocaleFromCode.js ${{\color{Goldenrod}{ ▏ }}}$ 0.6%, 84 B
dist/utilities/sanitizeID.js ${{\color{Goldenrod}{ ▏ }}}$ 0.6%, 77 B
dist/utilities/isEditing.js ${{\color{Goldenrod}{ }}}$ 0.4%, 59 B
(other) ${{\color{Goldenrod}{ ███████████████████▎ }}}$ 77.1%, 10.49 KB
Details

Next to the size is how much the size has increased or decreased compared with the base branch of this PR.

  • ‼️: Size increased by 20% or more. Special attention should be given to this.
  • ⚠️: Size increased in acceptable range (lower than 20%).
  • ✅: No change or even downsized.
  • 🗑️: The out file is deleted: not found in base branch.
  • 🆕: The out file is newly found: will be added to base branch.

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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants