Skip to content

Commit d2efca0

Browse files
authored
fix: prevent numerous transition/animation memory leaks (#12759)
* fix: prevent numerous transition/animation memory leaks * address feedback * tweak
1 parent ba116a1 commit d2efca0

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

.changeset/silly-masks-exist.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: prevent numerous transition/animation memory leaks

packages/svelte/src/internal/client/dom/elements/transitions.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ export function transition(flags, element, get_fn, get_params) {
222222
1,
223223
() => {
224224
dispatch_event(element, 'introend');
225+
// Ensure we cancel the animation to prevent leaking
226+
intro?.abort();
225227
intro = current_options = undefined;
226228
},
227229
is_both
@@ -249,6 +251,8 @@ export function transition(flags, element, get_fn, get_params) {
249251
0,
250252
() => {
251253
dispatch_event(element, 'outroend');
254+
// Ensure we cancel the animation to prevent leaking
255+
outro?.abort();
252256
outro = current_options = undefined;
253257
fn?.();
254258
},
@@ -322,16 +326,21 @@ function animate(element, options, counterpart, t2, on_finish, on_abort) {
322326
// once DOM has been updated...
323327
/** @type {Animation} */
324328
var a;
329+
var aborted = false;
325330

326331
queue_micro_task(() => {
332+
if (aborted) return;
327333
var o = options({ direction: is_intro ? 'in' : 'out' });
328334
a = animate(element, o, counterpart, t2, on_finish, on_abort);
329335
});
330336

331337
// ...but we want to do so without using `async`/`await` everywhere, so
332338
// we return a facade that allows everything to remain synchronous
333339
return {
334-
abort: () => a.abort(),
340+
abort: () => {
341+
aborted = true;
342+
a?.abort();
343+
},
335344
deactivate: () => a.deactivate(),
336345
reset: () => a.reset(),
337346
t: (now) => a.t(now)

playgrounds/demo/index.html

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
const component = render(App, {
2121
target: document.getElementById('root')
2222
});
23-
24-
// @ts-ignore
25-
window.unmount = () => unmount(component);
2623
</script>
2724
</body>
2825
</html>

0 commit comments

Comments
 (0)