From b8a8246c229424421c6d037a620e87f521e795f8 Mon Sep 17 00:00:00 2001 From: Elena Stoeva Date: Sun, 25 Feb 2024 01:42:14 +0000 Subject: [PATCH] [Advanced Settings] Fix code editor field --- .../field_input/input/code_editor_input.tsx | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/kbn-management/settings/components/field_input/input/code_editor_input.tsx b/packages/kbn-management/settings/components/field_input/input/code_editor_input.tsx index 101ac8897bb28..295425006d8ca 100644 --- a/packages/kbn-management/settings/components/field_input/input/code_editor_input.tsx +++ b/packages/kbn-management/settings/components/field_input/input/code_editor_input.tsx @@ -90,14 +90,17 @@ export const CodeEditorInput = ({ ); const debouncedUpdateValue = useMemo(() => { - // Trigger update 1000 ms after the user stopped typing to reduce validation requests to the server - return debounce(updateValue, 1000); + // Trigger update 500 ms after the user stopped typing to reduce validation requests to the server + return debounce(updateValue, 500); }, [updateValue]); const onChange: CodeEditorProps['onChange'] = async (newValue) => { - // @ts-expect-error - setValue(newValue); - await debouncedUpdateValue(newValue, onUpdate); + // Only update the value when the onChange handler is called with a different value from the current one + if (newValue !== value) { + // @ts-expect-error + setValue(newValue); + await debouncedUpdateValue(newValue, onUpdate); + } }; useEffect(() => {