Skip to content

Commit bffb9ef

Browse files
fix(ui): saving empty code editor throw error (#14019)
Fixes #14006 When attempting to save an empty code editor an error would throw because `value` was undefined.
1 parent ece5a95 commit bffb9ef

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

packages/ui/src/elements/CodeEditor/CodeEditor.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ const CodeEditor: React.FC<Props> = (props) => {
4747

4848
React.useEffect(() => {
4949
if (recalculatedHeightAt && recalculatedHeightAt > prevCalculatedHeightAt.current) {
50-
setDynamicHeight(Math.max(MIN_HEIGHT, value.split('\n').length * 18 + 2 + paddingFromProps))
50+
setDynamicHeight(
51+
value
52+
? Math.max(MIN_HEIGHT, value.split('\n').length * 18 + 2 + paddingFromProps)
53+
: MIN_HEIGHT,
54+
)
5155
prevCalculatedHeightAt.current = recalculatedHeightAt
5256
}
5357
}, [value, MIN_HEIGHT, paddingFromProps, recalculatedHeightAt])
@@ -81,7 +85,11 @@ const CodeEditor: React.FC<Props> = (props) => {
8185
height={maxHeight ? Math.min(dynamicHeight, maxHeight) : dynamicHeight}
8286
onChange={(value, ev) => {
8387
rest.onChange?.(value, ev)
84-
setDynamicHeight(Math.max(MIN_HEIGHT, value.split('\n').length * 18 + 2 + paddingFromProps))
88+
setDynamicHeight(
89+
value
90+
? Math.max(MIN_HEIGHT, value.split('\n').length * 18 + 2 + paddingFromProps)
91+
: MIN_HEIGHT,
92+
)
8593
}}
8694
onMount={(editor, monaco) => {
8795
rest.onMount?.(editor, monaco)

0 commit comments

Comments
 (0)