bugfix: fixed subgraph not being preserved after navigation

This commit is contained in:
2026-03-06 08:44:19 +01:00
parent 5b991ca8cd
commit e1adf6b9b0
2 changed files with 155 additions and 1 deletions

View File

@@ -68,8 +68,11 @@ export default function Graph({ setGraphPath }: { setGraphPath: React.Dispatch<R
const [contextMenuOpened, openContextMenu] = useState(false);
const [renameModalOpened, openRenameModal] = useState(false);
const [graphId, selectGraphId] = useState('main');
const graphIdRef = useRef(graphId);
const [graphsPath, setGraphsPath] = useState([createPathSegment('main', 'Main')])
const [nodeContext, openNodeContext] = useState<null | NodeContext>(null);
const [nodeContext, openNodeContext] = useState<null | NodeContext>(null);
graphIdRef.current = graphId;
const graphContextValue = {
graphId: graphId,
selectGraphId: selectGraphId,
@@ -92,6 +95,15 @@ export default function Graph({ setGraphPath }: { setGraphPath: React.Dispatch<R
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [graph]);
// Persist graph edits to the store so they survive breadcrumb navigation.
// We intentionally read graphId via ref (not as a dep) so this effect only
// fires on graph content changes, never on navigation (graphId changes).
useEffect(() => {
const state = useGraphsStore.getState() as { graphsById: Map<string, GraphModel> };
state.graphsById.set(graphIdRef.current, graph);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [graph]);
useEffect(() => {
if (nodeContext) {
openContextMenu(true);