mirror of
https://github.com/OFFIS-ESC/constellation-analyzer
synced 2026-01-27 07:43:41 +00:00
fix: clear graph editor when no document is active
Fixes an issue where nodes from a previous document would persist when creating a new document after closing all documents. The problem occurred because: 1. When all documents were closed (activeDocumentId becomes null), the graph store wasn't being cleared 2. When a new document was created, stale data from the old document could contaminate the new document through race conditions Changes: - Clear nodes and edges from graph store when activeDocumentId is null - Add safeguard to prevent saving stale graph data to newly created documents before they've been fully loaded - Maintain proper state tracking to prevent cross-document contamination 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
99ab514c0c
commit
09b62c69bd
1 changed files with 32 additions and 0 deletions
|
|
@ -81,6 +81,31 @@ export function useActiveDocument() {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
isLoadingRef.current = false;
|
isLoadingRef.current = false;
|
||||||
}, 100);
|
}, 100);
|
||||||
|
} else if (!activeDocumentId) {
|
||||||
|
// Clear graph store when no document is active
|
||||||
|
console.log('No active document, clearing graph editor');
|
||||||
|
|
||||||
|
// Set loading flag to prevent dirty marking during clear
|
||||||
|
isLoadingRef.current = true;
|
||||||
|
lastLoadedDocIdRef.current = null;
|
||||||
|
|
||||||
|
setNodes([]);
|
||||||
|
setEdges([]);
|
||||||
|
// Note: We keep nodeTypes and edgeTypes so they're available for new documents
|
||||||
|
|
||||||
|
// Clear the last synced state
|
||||||
|
lastSyncedStateRef.current = {
|
||||||
|
documentId: null,
|
||||||
|
nodes: [],
|
||||||
|
edges: [],
|
||||||
|
nodeTypes: [],
|
||||||
|
edgeTypes: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
// Clear loading flag after a brief delay
|
||||||
|
setTimeout(() => {
|
||||||
|
isLoadingRef.current = false;
|
||||||
|
}, 100);
|
||||||
}
|
}
|
||||||
}, [activeDocumentId, activeDocument, documents, setNodes, setEdges, setNodeTypes, setEdgeTypes]);
|
}, [activeDocumentId, activeDocument, documents, setNodes, setEdges, setNodeTypes, setEdgeTypes]);
|
||||||
|
|
||||||
|
|
@ -101,6 +126,13 @@ export function useActiveDocument() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CRITICAL: Prevent saving stale data to new documents
|
||||||
|
// If the last loaded document doesn't match the active document, skip this check
|
||||||
|
if (lastLoadedDocIdRef.current !== activeDocumentId) {
|
||||||
|
console.log(`Skipping dirty check - document hasn't been loaded yet (last loaded: ${lastLoadedDocIdRef.current}, active: ${activeDocumentId})`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Mark document as dirty when graph changes
|
// Mark document as dirty when graph changes
|
||||||
const hasChanges =
|
const hasChanges =
|
||||||
JSON.stringify(graphNodes) !== JSON.stringify(lastSyncedStateRef.current.nodes) ||
|
JSON.stringify(graphNodes) !== JSON.stringify(lastSyncedStateRef.current.nodes) ||
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue