-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Layout with transition not unmounted on navigation #7405
Comments
While waiting for a fix, you can workaround this by adding <script>
import { page } from '$app/stores';
import { slide } from 'svelte/transition';
$: isB = $page.url.pathname === '/b';
</script>
<slot />
{#if isB}
- <li transition:slide><a href="/a"><code>/a</code></a> - <code>/b/+layout.svelte</code></li>
+ <li transition:slide|local><a href="/a"><code>/a</code></a> - <code>/b/+layout.svelte</code></li>
{/if} But either way, a very interesting bug. I've had similar troubles with navigation and using transitions, but adding local usually fixes them. However, it's still confusing when it happened to me while I was learning Svelte. |
Are you able to identify the cause? Personally curious |
nope. |
Update: found some transitions buried in a component I forgot about 😅 adding the In tracking it down, looked like something between |
I have made a reproducible example (albeit a bit bigger than needed) if you want to play with it: https://stackblitz.com/edit/sveltejs-kit-template-default-1fsbnb |
I can't track this down to a recent kit version, going back as far as 450 still reproduces this. I think the issue lies in Svelte core. I can reproduce this with a simple variable that is updated every 10 miliseconds. My guess is that updating the value while transitioning out breaks things. <script>
import { slide } from 'svelte/transition';
let foo = {t:true}
setInterval(() => foo={t:true}, 10);
</script>
<slot />
{#if foo.t}
<li transition:slide><a href="/a"><code>/a</code></a> - <code>/b/+layout.svelte</code></li>
{/if} |
possibly related - #7877 |
Pls Fix! |
ugh, just ran into this. very strange bug. pls fix! |
- cleanup + webgl planes correctly removed, removed hacks
I also noticed that one of my pages took 500ms to disappear when navigating out. I tracked it to a component I was using which was using a transition that was not |
It seems to be fixed with Svelte 5. Here's an updated repro. I just updated all dependencies to their latest. |
While there may be multiple issues at play (see the many bug reports dealing with transitions), let me clarify what I believe I encountered. If a Svelte 3 page/layout uses a third-party component (such as svelte-video-player in my case) which internally uses a non-local transition on any of its components, then this transition plays when the page contained the component is destroyed - this is probably as it should be, although likely the developer of the component didn't intend this, and it's creating problems for the user of the component because they have no way to override the transition (let alone that it's confusing and takes a long time to figure out). But what's clearly a bug (in Svelte 3, probably) is this: not only does the transition play (and delay the hiding of the page that the component is in), but the new page that's being navigated to has already appeared even before all components in the old page have been transitioned out. It appeared under the previous one as described by @mglikesbikes. In my case, the old page/layout did eventually disappear after playing its transition (so this may not be quite the bug described here where the old page doesn't get destroyed at all). I think the reason they made transitions local by default in Svelte 4 may be this, which is to avoid such unintended effects of components on the pages/layouts containing them. |
Closing as fixed in svelte 5 |
Describe the bug
When routing from
/b
to/
using an anchor element, the/b/+page.svelte
component does not get unmounted./routes/b
related components should be unmounted.<div><a href="/">Home</a></div>
component remains.Reproduction
Check Stackblitz
Instructions
/b
/a
Expected behavior
Actual behavior
Logs
No response
System Info
Severity
annoyance
Additional Information
The text was updated successfully, but these errors were encountered: