From 5f597961c61372e5e2e9a85c0b92126d9b592484 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Mon, 9 Mar 2026 14:10:27 +0800 Subject: [PATCH] Fix cytoscapeStore: preserve positions, guard access, remove redundant write Co-Authored-By: Claude Opus 4.6 --- src/stores/cytoscapeStore.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/stores/cytoscapeStore.ts b/src/stores/cytoscapeStore.ts index 470d54a..f04979a 100644 --- a/src/stores/cytoscapeStore.ts +++ b/src/stores/cytoscapeStore.ts @@ -64,7 +64,6 @@ export const useCytoscapeStore = defineStore('cytoscapeStore', { } else { this.nodePositions[this.currentGraphId][direction] .push({ id: nodeId, position: position }); - localStorage.setItem(SAVE_KEY_NAME, JSON.stringify(this.nodePositions)); } this.savePositionsToStorage(); }, @@ -73,6 +72,7 @@ export const useCytoscapeStore = defineStore('cytoscapeStore', { * @param {string} direction - Layout direction ('TB' or 'LR'). */ loadPositionsFromStorage(direction: string) { + if (!this.nodePositions[this.currentGraphId]) return; try { const raw = localStorage.getItem(SAVE_KEY_NAME); if (raw) { @@ -94,12 +94,9 @@ export const useCytoscapeStore = defineStore('cytoscapeStore', { }, setCurrentGraphId(currentGraphId: string) { this.currentGraphId = currentGraphId; - this.nodePositions = { - [this.currentGraphId]: { - 'TB': [], - 'LR': [], - } - }; + if (!this.nodePositions[currentGraphId]) { + this.nodePositions[currentGraphId] = { TB: [], LR: [] }; + } }, }, }); \ No newline at end of file