Skip to content

fix: prevent numerous transition/animation memory leaks #12759

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/silly-masks-exist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: prevent numerous transition/animation memory leaks
11 changes: 10 additions & 1 deletion packages/svelte/src/internal/client/dom/elements/transitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ export function transition(flags, element, get_fn, get_params) {
1,
() => {
dispatch_event(element, 'introend');
// Ensure we cancel the animation to prevent leaking
intro?.abort();
intro = current_options = undefined;
},
is_both
Expand Down Expand Up @@ -249,6 +251,8 @@ export function transition(flags, element, get_fn, get_params) {
0,
() => {
dispatch_event(element, 'outroend');
// Ensure we cancel the animation to prevent leaking
outro?.abort();
outro = current_options = undefined;
fn?.();
},
Expand Down Expand Up @@ -322,16 +326,21 @@ function animate(element, options, counterpart, t2, on_finish, on_abort) {
// once DOM has been updated...
/** @type {Animation} */
var a;
var aborted = false;

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

// ...but we want to do so without using `async`/`await` everywhere, so
// we return a facade that allows everything to remain synchronous
return {
abort: () => a.abort(),
abort: () => {
aborted = true;
a?.abort();
},
deactivate: () => a.deactivate(),
reset: () => a.reset(),
t: (now) => a.t(now)
Expand Down
3 changes: 0 additions & 3 deletions playgrounds/demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
const component = render(App, {
target: document.getElementById('root')
});

// @ts-ignore
window.unmount = () => unmount(component);
</script>
</body>
</html>
Loading