fix: resolve stale closure causing breadcrumbs to disappear on back-navigation (closes #2)
The onClick handler in createPathSegment closed over the graphsPath variable from the render when the segment was created. By the time a breadcrumb was clicked (after further navigation), that closure was stale, so findIndex returned -1 and splice(0) wiped the entire breadcrumb array. Fix: use the functional updater form of setGraphsPath so findIndex runs against the current state rather than a stale snapshot. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -264,12 +264,7 @@ const Graph = forwardRef<GraphHandle, { setGraphPath: React.Dispatch<React.SetSt
|
|||||||
title: selectedNodeName,
|
title: selectedNodeName,
|
||||||
key: pathSegmentId,
|
key: pathSegmentId,
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
const index = graphsPath.findIndex(p => p.key === pathSegmentId);
|
setGraphsPath(prev => prev.slice(0, prev.findIndex(p => p.key === pathSegmentId) + 1));
|
||||||
setGraphsPath(prev => {
|
|
||||||
prev.splice(index + 1);
|
|
||||||
|
|
||||||
return [...prev];
|
|
||||||
});
|
|
||||||
selectGraphId(pathSegmentId);
|
selectGraphId(pathSegmentId);
|
||||||
}
|
}
|
||||||
} as BreadcrumbItemType;
|
} as BreadcrumbItemType;
|
||||||
|
|||||||
Reference in New Issue
Block a user