Skip to content

Commit

Permalink
tweak logic
Browse files Browse the repository at this point in the history
  • Loading branch information
amcdnl committed Mar 18, 2024
1 parent 104133d commit 36c0e34
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/CameraControls/useCenterGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,16 @@ export const useCenterGraph = ({

useLayoutEffect(() => {
async function load() {
// Center the graph once nodes are loaded on mount
if (controls && nodes?.length && !mounted.current) {
await centerNodes(nodes, false);
mounted.current = true;
// If node positions have changed and some aren't in view, center the graph
} else if (controls && nodes?.length) {
await centerNodes(nodes, animated);
// Once we've loaded controls and we have nodes, let's recenter
if (controls && nodes?.length) {
if (!mounted.current) {
// Center the graph once nodes are loaded on mount
await centerNodes(nodes, false);
mounted.current = true;
} else {
// If node positions have changed and some aren't in view, center the graph
await centerNodes(nodes, animated);
}
}
}

Expand Down

0 comments on commit 36c0e34

Please sign in to comment.