From b9c9bb548dc0e7d6fdb939dfb568fccab231895c Mon Sep 17 00:00:00 2001 From: chihlasm Date: Mon, 13 Apr 2026 20:03:35 +0000 Subject: [PATCH] fix(network): force re-render on undo/redo so canUndo/canRedo stay accurate Co-Authored-By: Claude Sonnet 4.6 --- frontend/src/pages/NetworkDiagrams/DiagramEditor.tsx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/frontend/src/pages/NetworkDiagrams/DiagramEditor.tsx b/frontend/src/pages/NetworkDiagrams/DiagramEditor.tsx index 0286ff36..b08bafa2 100644 --- a/frontend/src/pages/NetworkDiagrams/DiagramEditor.tsx +++ b/frontend/src/pages/NetworkDiagrams/DiagramEditor.tsx @@ -1,4 +1,4 @@ -import { useState, useCallback, useEffect, useRef } from 'react' +import { useState, useCallback, useEffect, useRef, useReducer } from 'react' import { useParams, useNavigate } from 'react-router-dom' import { ReactFlowProvider, @@ -74,6 +74,7 @@ function DiagramEditorInner() { const historyStack = useRef<{ nodes: Node[]; edges: Edge[] }[]>([]) const historyIndex = useRef(-1) const MAX_HISTORY = 50 + const [, forceHistoryUpdate] = useReducer((x: number) => x + 1, 0) const pushHistory = useCallback((currentNodes: Node[], currentEdges: Edge[]) => { historyStack.current = historyStack.current.slice(0, historyIndex.current + 1) @@ -86,7 +87,8 @@ function DiagramEditorInner() { } else { historyIndex.current += 1 } - }, []) + forceHistoryUpdate() + }, [forceHistoryUpdate]) const undo = useCallback(() => { if (historyIndex.current <= 0) return @@ -95,7 +97,8 @@ function DiagramEditorInner() { setNodes(snapshot.nodes) setEdges(snapshot.edges) setIsDirty(true) - }, [setNodes, setEdges]) + forceHistoryUpdate() + }, [setNodes, setEdges, forceHistoryUpdate]) const redo = useCallback(() => { if (historyIndex.current >= historyStack.current.length - 1) return @@ -104,7 +107,8 @@ function DiagramEditorInner() { setNodes(snapshot.nodes) setEdges(snapshot.edges) setIsDirty(true) - }, [setNodes, setEdges]) + forceHistoryUpdate() + }, [setNodes, setEdges, forceHistoryUpdate]) const canUndo = historyIndex.current > 0 const canRedo = historyIndex.current < historyStack.current.length - 1