diff --git a/src/platform/packages/private/kbn-esql-editor/src/esql_editor.tsx b/src/platform/packages/private/kbn-esql-editor/src/esql_editor.tsx index 2a870978c4bcb..b72ad926ae6a5 100644 --- a/src/platform/packages/private/kbn-esql-editor/src/esql_editor.tsx +++ b/src/platform/packages/private/kbn-esql-editor/src/esql_editor.tsx @@ -170,9 +170,13 @@ export const ESQLEditor = memo(function ESQLEditor({ }); const onQueryUpdate = useCallback( (value: string) => { + if (!editorIsInline) { + // preventing a race condition in the inline editor mode + setCode(value); + } onTextLangQueryChange({ esql: value } as AggregateQuery); }, - [onTextLangQueryChange] + [onTextLangQueryChange, setCode, editorIsInline] ); const onQuerySubmit = useCallback(() => { @@ -224,11 +228,11 @@ export const ESQLEditor = memo(function ESQLEditor({ useEffect(() => { if (editor1.current) { - if (code !== fixedQuery) { + if (code !== fixedQuery && (editorIsInline || !isQueryLoading)) { setCode(fixedQuery); } } - }, [code, fixedQuery]); + }, [code, fixedQuery, isQueryLoading, editorIsInline]); // Enable the variables service if the feature is supported in the consumer app useEffect(() => {