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.
This commit is contained in:
@@ -47,7 +47,11 @@ const CodeEditor: React.FC<Props> = (props) => {
|
|||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (recalculatedHeightAt && recalculatedHeightAt > prevCalculatedHeightAt.current) {
|
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
|
prevCalculatedHeightAt.current = recalculatedHeightAt
|
||||||
}
|
}
|
||||||
}, [value, MIN_HEIGHT, paddingFromProps, recalculatedHeightAt])
|
}, [value, MIN_HEIGHT, paddingFromProps, recalculatedHeightAt])
|
||||||
@@ -81,7 +85,11 @@ const CodeEditor: React.FC<Props> = (props) => {
|
|||||||
height={maxHeight ? Math.min(dynamicHeight, maxHeight) : dynamicHeight}
|
height={maxHeight ? Math.min(dynamicHeight, maxHeight) : dynamicHeight}
|
||||||
onChange={(value, ev) => {
|
onChange={(value, ev) => {
|
||||||
rest.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) => {
|
onMount={(editor, monaco) => {
|
||||||
rest.onMount?.(editor, monaco)
|
rest.onMount?.(editor, monaco)
|
||||||
|
|||||||
Reference in New Issue
Block a user