From 017854955df4096c303af45a41be7da588046b09 Mon Sep 17 00:00:00 2001 From: "kasia.oczkowska" Date: Fri, 21 Jun 2024 10:37:39 +0100 Subject: [PATCH] fix: persist value in ControlledCustomAutocomplete when it depends on other fields --- .../ControlledCustomAutocomplete/index.jsx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/web/src/components/ControlledCustomAutocomplete/index.jsx b/packages/web/src/components/ControlledCustomAutocomplete/index.jsx index 874ee6a9..9e36dbb6 100644 --- a/packages/web/src/components/ControlledCustomAutocomplete/index.jsx +++ b/packages/web/src/components/ControlledCustomAutocomplete/index.jsx @@ -61,6 +61,7 @@ function ControlledCustomAutocomplete(props) { const [isSingleChoice, setSingleChoice] = React.useState(undefined); const priorStepsWithExecutions = React.useContext(StepExecutionsContext); const editorRef = React.useRef(null); + const mountedRef = React.useRef(false); const renderElement = React.useCallback( (props) => , @@ -94,10 +95,14 @@ function ControlledCustomAutocomplete(props) { }, []); React.useEffect(() => { - const hasDependencies = dependsOnValues.length; - if (hasDependencies) { - // Reset the field when a dependent has been updated - resetEditor(editor); + if (mountedRef.current) { + const hasDependencies = dependsOnValues.length; + if (hasDependencies) { + // Reset the field when a dependent has been updated + resetEditor(editor); + } + } else { + mountedRef.current = true; } }, dependsOnValues);