From bffb9ef8b9cfa2305e97594160c1a135392b98a1 Mon Sep 17 00:00:00 2001 From: Jarrod Flesch <30633324+JarrodMFlesch@users.noreply.github.com> Date: Thu, 2 Oct 2025 17:31:45 -0400 Subject: [PATCH] fix(ui): saving empty code editor throw error (#14019) Fixes https://github.com/payloadcms/payload/issues/14006 When attempting to save an empty code editor an error would throw because `value` was undefined. --- packages/ui/src/elements/CodeEditor/CodeEditor.tsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/ui/src/elements/CodeEditor/CodeEditor.tsx b/packages/ui/src/elements/CodeEditor/CodeEditor.tsx index 71153103b..e4228bc35 100644 --- a/packages/ui/src/elements/CodeEditor/CodeEditor.tsx +++ b/packages/ui/src/elements/CodeEditor/CodeEditor.tsx @@ -47,7 +47,11 @@ const CodeEditor: React.FC = (props) => { React.useEffect(() => { if (recalculatedHeightAt && recalculatedHeightAt > prevCalculatedHeightAt.current) { - setDynamicHeight(Math.max(MIN_HEIGHT, value.split('\n').length * 18 + 2 + paddingFromProps)) + setDynamicHeight( + value + ? Math.max(MIN_HEIGHT, value.split('\n').length * 18 + 2 + paddingFromProps) + : MIN_HEIGHT, + ) prevCalculatedHeightAt.current = recalculatedHeightAt } }, [value, MIN_HEIGHT, paddingFromProps, recalculatedHeightAt]) @@ -81,7 +85,11 @@ const CodeEditor: React.FC = (props) => { height={maxHeight ? Math.min(dynamicHeight, maxHeight) : dynamicHeight} onChange={(value, ev) => { rest.onChange?.(value, ev) - setDynamicHeight(Math.max(MIN_HEIGHT, value.split('\n').length * 18 + 2 + paddingFromProps)) + setDynamicHeight( + value + ? Math.max(MIN_HEIGHT, value.split('\n').length * 18 + 2 + paddingFromProps) + : MIN_HEIGHT, + ) }} onMount={(editor, monaco) => { rest.onMount?.(editor, monaco)