fix: improve deep cloning for graph and resampling to handle non-cloneable properties

This commit is contained in:
Marc Emmanuel 2026-03-26 10:51:30 +01:00
parent f2fc42799b
commit b80dc94e1b
3 changed files with 54 additions and 5 deletions

View file

@ -260,7 +260,14 @@ function getName(id) {
}
function getGraph(currentGraph) {
const newGraph = shouldRegenerateGrid(currentGraph, seed) ? generateGrid() : structuredClone(currentGraph);
if (shouldRegenerateGrid(currentGraph, seed)) return generateGrid();
// Deep clone avoiding non-cloneable properties (like D3 quadtrees with functions)
const newGraph = JSON.parse(JSON.stringify(currentGraph));
// Recreate voronoi cells since JSON doesn't preserve typed arrays or circular refs
const {cells, vertices} = calculateVoronoi(newGraph.points, newGraph.boundary);
newGraph.cells = cells;
newGraph.vertices = vertices;
delete newGraph.cells.h;
return newGraph;
}