bugfix: fixed subgraph not being preserved after navigation
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user