Skip to content

Commit 5295f06

Browse files
committed
Fix animation cancellation when loading new graph mid-animation
1 parent 85b6c06 commit 5295f06

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/lib/animation/assemblyAnimation.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,20 @@ export function runAssemblyAnimation(
172172
return;
173173
}
174174

175+
// Cancel any previous animation (important when loading new graph mid-animation)
176+
if (isActive || cleanupTimeoutId) {
177+
if (cleanupTimeoutId) {
178+
clearTimeout(cleanupTimeoutId);
179+
cleanupTimeoutId = null;
180+
}
181+
// Quick cleanup of old animation classes
182+
document.querySelectorAll('.assembling').forEach((el) => {
183+
el.classList.remove('assembling');
184+
});
185+
isActive = false;
186+
removeSkipListeners();
187+
}
188+
175189
// Hide everything immediately
176190
document.body.classList.add('assembly-pending');
177191

@@ -238,6 +252,12 @@ function calculateAnimationTiming(nodes: NodeInfo[], edges: EdgeInfo[], viewport
238252
edgeDelays.set(edge.id, bothNodesLanded);
239253
});
240254

255+
// Cancel any previous animation's cleanup timeout
256+
if (cleanupTimeoutId) {
257+
clearTimeout(cleanupTimeoutId);
258+
cleanupTimeoutId = null;
259+
}
260+
241261
isActive = true;
242262
addSkipListeners();
243263

0 commit comments

Comments
 (0)