Skip to content

Commit 09a6140

Browse files
authored
fix(richtext-lexical): do not run json.parse if value is undefined or null (#14385)
Fixes #14372 This prevents running `JSON.parse(JSON.stringify` against `undefined` or `null` values (`!= null` checks both `null` and `undefined`)
1 parent 059185f commit 09a6140

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

packages/richtext-lexical/src/field/Field.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,12 @@ const RichTextComponent: React.FC<
147147
// If we used JSON.stringify, the editor would re-mount every time you save the document, as the order of keys changes => change detected => re-mount.
148148
if (
149149
prevValueRef.current !== value &&
150-
!dequal(JSON.parse(JSON.stringify(prevValueRef.current)), value)
150+
!dequal(
151+
prevValueRef.current != null
152+
? JSON.parse(JSON.stringify(prevValueRef.current))
153+
: prevValueRef.current,
154+
value,
155+
)
151156
) {
152157
prevInitialValueRef.current = initialValue
153158
prevValueRef.current = value

0 commit comments

Comments
 (0)