-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
$destroy don't play outro transition #4056
Comments
I suppose this would be a proposal for an |
We should explain this feature in the documentation, otherwise more people may think this is a bug like me. |
But if this component was used inside of another Svelte component itself, wouldn't you instantiate it differently? as in have Svelte deal with the lifecycle hooks for you, rather than manually calling them? Because Svelte will handle the transitions accordingly this way. https://svelte.dev/repl/767db42208ad40efa56976f645e28ab8?version=3.16.0 |
I don't think you typically would be manually instantiating or destroying a component inside of another component - that's just what's required in the REPL. Having a way to play outro transitions while manually managing a component (the way you can have it play intro transitions) seems like a reasonable request. |
For everyone who needs a workaround for this: import type { SvelteComponent } from 'svelte';
import { check_outros, group_outros, transition_out } from 'svelte/internal';
// Workaround for https://github.com/sveltejs/svelte/issues/4056
const outroAndDestroy = (instance: SvelteComponent) => {
if (instance.$$.fragment && instance.$$.fragment.o) {
group_outros();
transition_out(instance.$$.fragment, 0, 0, () => {
instance.$destroy();
});
check_outros();
} else {
instance.$destroy();
}
}; Instead of calling |
@PatrickG could you provide a quick repl to show how you might use this? |
@PatrickG Thanks, it's works pretty good. @russellgoldenberg You can try this one: |
Just bit by this (sveltekit v1.0.0-next.71). I have some transitions on a page, and the out transition is firing when navigating to a new page. This makes navigation feel slow, as there's an additional x00ms delay while the transition finishes. This is somewhat unexpected - I did not expect component outro transitions to fire on nav. I can see how this is useful for top-level components (full page screen wipes and other effects), but it seems like the exceptional case rather than the default case. Interestingly, intro transitions don't seem to delay nav, only outros. |
That is not related to this issue. |
I'd rather not dig around in the Svelte internals. My workaround is to take a "destroyed" property and not literally destroy it but wrap all its markup in an So it's like: let toast = new Toast({
target: document.body,
props: {
text,
},
intro: true,
});
setTimeout(() => {
toast.$set({ destroyed: true });
}, 5000); Would love to just have an "outro" option though. |
Closed by #14540 |
Describe the bug
When call $destroy of a component instance, the dom node is removed imediatly without play outro transition.
Logs
nothing
To Reproduce
https://svelte.dev/repl/a9e6f228bf40490c843c639ef4288f38?version=3.16.0
Expected behavior
Play outro transition before remove.
The text was updated successfully, but these errors were encountered: