Skip to content

Commit df4af70

Browse files
authored
fix(richtext-lexical): ensure jsx and html converters do not output linebreak if editor is empty (#10563)
If you add text to the editor, then delete it using ctrl+a + delete, one empty paragraph that cannot be removed remains in the editor state. In order to account for this, we have a `hasText()` function - this, however, was not used in our JSX and HTML converters. This caused the converters to incorrectly output a linebreak if said empty editor state was passed in.
1 parent 90e1843 commit df4af70

File tree

2 files changed

+6
-2
lines changed
  • packages/richtext-lexical/src
    • exports/react/components/RichText/converter
    • features/converters/html/converter

2 files changed

+6
-2
lines changed

packages/richtext-lexical/src/exports/react/components/RichText/converter/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import React from 'react'
55
import type { SerializedBlockNode, SerializedInlineBlockNode } from '../../../../../nodeTypes.js'
66
import type { JSXConverter, JSXConverters, SerializedLexicalNodeWithParent } from './types.js'
77

8+
import { hasText } from '../../../../../validate/hasText.js'
9+
810
export type ConvertLexicalToHTMLArgs = {
911
converters: JSXConverters
1012
data: SerializedEditorState
@@ -18,7 +20,7 @@ export function convertLexicalToJSX({
1820
disableIndent,
1921
disableTextAlign,
2022
}: ConvertLexicalToHTMLArgs): React.ReactNode {
21-
if (data?.root?.children?.length) {
23+
if (hasText(data)) {
2224
return convertLexicalNodesToJSX({
2325
converters,
2426
disableIndent,

packages/richtext-lexical/src/features/converters/html/converter/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { createLocalReq } from 'payload'
55

66
import type { HTMLConverter, SerializedLexicalNodeWithParent } from './types.js'
77

8+
import { hasText } from '../../../../validate/hasText.js'
9+
810
export type ConvertLexicalToHTMLArgs = {
911
converters: HTMLConverter[]
1012
currentDepth?: number
@@ -53,7 +55,7 @@ export async function convertLexicalToHTML({
5355
req,
5456
showHiddenFields,
5557
}: ConvertLexicalToHTMLArgs): Promise<string> {
56-
if (data?.root?.children?.length) {
58+
if (hasText(data)) {
5759
if (req === undefined && payload) {
5860
req = await createLocalReq({}, payload)
5961
}

0 commit comments

Comments
 (0)