mirror of
https://github.com/dagu-org/dagu.git
synced 2025-12-28 06:34:22 +00:00
fix(ui): keep editing state while polling (#1290)
This commit is contained in:
parent
360a988b8e
commit
d88e3f957a
@ -51,6 +51,7 @@ function DAGSpec({ fileName }: Props) {
|
||||
|
||||
// Reference to the main container div
|
||||
const containerRef = React.useRef<HTMLDivElement>(null);
|
||||
const lastFetchedSpecRef = React.useRef<string | undefined>(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(() => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user