From b431839bcea7e4b9c089a3ede7bb74725d6b6fcf Mon Sep 17 00:00:00 2001 From: Lucas Oliveira Date: Thu, 19 Oct 2023 17:20:21 -0300 Subject: [PATCH] Fixed bug where it does not open and does not save correctly --- src/frontend/src/contexts/undoRedoContext.tsx | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/frontend/src/contexts/undoRedoContext.tsx b/src/frontend/src/contexts/undoRedoContext.tsx index 83dfd8f32..d348d12c3 100644 --- a/src/frontend/src/contexts/undoRedoContext.tsx +++ b/src/frontend/src/contexts/undoRedoContext.tsx @@ -54,11 +54,21 @@ export function UndoRedoProvider({ children }) { // push the current graph to the past state setPast((old) => { let newPast = cloneDeep(old); - newPast[tabIndex] = old[tabIndex].slice( - old[tabIndex].length - defaultOptions.maxHistorySize + 1, - old[tabIndex].length - ); - newPast[tabIndex].push({ nodes: getNodes(), edges: getEdges() }); + let newState = { + nodes: cloneDeep(getNodes()), + edges: cloneDeep(getEdges()), + }; + if ( + old[tabIndex] && + JSON.stringify(old[tabIndex][old[tabIndex].length - 1]) !== + JSON.stringify(newState) + ) { + newPast[tabIndex] = old[tabIndex].slice( + old[tabIndex].length - defaultOptions.maxHistorySize + 1, + old[tabIndex].length + ); + newPast[tabIndex].push(newState); + } return newPast; });