fix(richtext-lexical): preserve hard line breaks on markdown import - #17061
Merged
Conversation
Backports lexical PR #8402 into Payload's forked @lexical/markdown. CommonMark hard line breaks (two-or-more trailing spaces or a trailing backslash) were silently merged into the previous line during $convertFromMarkdownString import. The marker is now detected during normalization/import, stripped from the text, and stored on the LineBreakNode via node state so it round trips on export. The upstream resetOnCopyNode option is omitted because it does not exist in the pinned lexical@0.41.0.
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.
|
Mirrors lexical PR #8402 coverage for hard line breaks that follow formatted text and links, where the trailing-space marker is split into its own text node and must be moved onto the LineBreakNode. Exercises the hasNonWhitespaceContentOnLine branch that the original tests did not cover.
r1tsuu
approved these changes
Jun 19, 2026
Contributor
|
🚀 This is included in version v3.85.2 |
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.
Summary
Markdown imported via
$convertFromMarkdownStringsilently dropped CommonMark hard line breaks: a line ending in two-or-more trailing spaces or a trailing backslash was merged into the previous line as a soft wrap, losing the intended<br>.This backports the relevant parts of upstream lexical PR #8402 into Payload's forked
@lexical/markdown. We maintain a fork of@lexical/markdown(rather than re-exporting it), and it is pinned tolexical@0.41.0, so the upstream fix (shipped in0.45.0) is not picked up by a dependency bump alone.This is the 3.x backport. The equivalent v4 PR is #17060.
What changed
MarkdownTransformers.tsparseMarkdownHardLineBreakto detect a trailing\or 2+ spaces marker.hardLineBreakStatenode-state config and$createMarkdownLineBreakNode, which strips the marker from the text and stores it on the createdLineBreakNode.normalizeMarkdownno longer merges a following line into a line that ends with a hard break marker, and preserves the marker when merging.QUOTEtransformer uses$createMarkdownLineBreakNodefor multi-line quote joins.MarkdownImport.tsuses$createMarkdownLineBreakNodeinstead of a plain$createLineBreakNodewhen joining adjacent blocks.MarkdownExport.tsre-emits the stored marker (\nor\\\n) on export so the value round trips; line breaks without a marker still export as a plain\n(unchanged behavior).Note on
resetOnCopyNodeUpstream sets
resetOnCopyNode: trueon the node state. That option does not exist inlexical@0.41.0(it was added in0.42.0), so it is intentionally omitted here. It only affects copy/paste node duplication and is not required for correct markdown import/export.Test plan
LexicalMarkdownHardLineBreak.spec.tscovering normalization, import (marker stripped +LineBreakNodecreated), and export round trip for both the trailing-spaces and backslash forms, plus a soft-wrap regression check.vitest --project unitfor the new spec passes (10/10) on this 3.x branch.eslint+prettierclean on changed files.