From d88e3f957a3f8ab30224a428cf2d282fa1cdf247 Mon Sep 17 00:00:00 2001 From: YotaHamada Date: Wed, 1 Oct 2025 16:22:57 +0900 Subject: [PATCH] fix(ui): keep editing state while polling (#1290) --- .../dags/components/dag-editor/DAGSpec.tsx | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/ui/src/features/dags/components/dag-editor/DAGSpec.tsx b/ui/src/features/dags/components/dag-editor/DAGSpec.tsx index d1233052..f0041477 100644 --- a/ui/src/features/dags/components/dag-editor/DAGSpec.tsx +++ b/ui/src/features/dags/components/dag-editor/DAGSpec.tsx @@ -51,6 +51,7 @@ function DAGSpec({ fileName }: Props) { // Reference to the main container div const containerRef = React.useRef(null); + const lastFetchedSpecRef = React.useRef(undefined); /** * Handle flowchart direction change and save preference to cookie @@ -100,10 +101,21 @@ function DAGSpec({ fileName }: Props) { // Update current value when data changes useEffect(() => { - if (data) { - setCurrentValue(data.spec); + if (typeof data?.spec === 'undefined') { + return; } - }, [data]); + + const fetchedSpec = data.spec; + + if (lastFetchedSpecRef.current === fetchedSpec) { + // Ensure the editor initializes with the fetched value on first load. + setCurrentValue((prev) => (typeof prev === 'undefined' ? fetchedSpec : prev)); + return; + } + + lastFetchedSpecRef.current = fetchedSpec; + setCurrentValue(fetchedSpec); + }, [data?.spec]); // Save scroll position before saving const saveScrollPosition = React.useCallback(() => {