From 9b9ee76bcc3d2e8341b3f5828024c6ef38be4567 Mon Sep 17 00:00:00 2001 From: lawvs <18554747+lawvs@users.noreply.github.com> Date: Thu, 6 Nov 2025 15:32:15 +0800 Subject: [PATCH] fix: handle undefined initialValue and check for empty JSON root --- .../ui/lexical-rich-editor/LexicalRichEditorTextArea.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/internal/components/src/ui/lexical-rich-editor/LexicalRichEditorTextArea.tsx b/packages/internal/components/src/ui/lexical-rich-editor/LexicalRichEditorTextArea.tsx index 97b790360..03d59abc4 100644 --- a/packages/internal/components/src/ui/lexical-rich-editor/LexicalRichEditorTextArea.tsx +++ b/packages/internal/components/src/ui/lexical-rich-editor/LexicalRichEditorTextArea.tsx @@ -58,12 +58,16 @@ export const LexicalRichEditorTextArea = ({ // Create initial editor state from saved value const initialEditorState = useMemo(() => { - if (!initialValue) return null + if (initialValue === undefined) return null // Try to parse as JSON state first try { - JSON.parse(initialValue) // If successful, it's already a JSON state + const json = JSON.parse(initialValue) + // Check if it has root and children + if (!("root" in json) || !("children" in json.root) || json.root.children.length === 0) { + return getEditorStateJSONString("") + } return initialValue } catch { // If parsing fails, it's plain text, convert it