Layout with transition not unmounted on navigation
See original GitHub issueDescribe the bug
When routing from /b
to /
using an anchor element, the /b/+page.svelte
component does not get unmounted.
<!-- /routes/b/+layout.svelte -->
<script>
import { page } from '$app/stores';
import { slide } from 'svelte/transition';
$: isB = $page.url.pathname === '/b';
</script>
<slot />
{#if isB}
<div transition:slide><a href="/">Home</a></div>
{/if}
<!-- /routes/b/+page.svelte -->
<div><a href="/">Home</a></div>
- Expected behavior: all
/routes/b
related components should be unmounted. - Actual behavior: the
<div><a href="/">Home</a></div>
component remains.
Reproduction
Check Stackblitz
Instructions
- Press
/b
- Press
/a
Expected behavior
/a
/b - /a/+page.svelte
Actual behavior
/a
/a - /b/+page.svelte
/b - /a/+page.svelte
Logs
No response
System Info
System:
OS: Windows 10 10.0.22621
CPU: (8) x64 AMD Ryzen 7 4700U with Radeon Graphics
Memory: 3.79 GB / 15.32 GB
Binaries:
Node: 18.12.0 - C:\Program Files\nodejs\node.EXE
npm: 8.19.2 - C:\Program Files\nodejs\npm.CMD
Browsers:
Edge: Spartan (44.22621.675.0), Chromium (105.0.1343.53)
Internet Explorer: 11.0.22621.1
Severity
annoyance
Additional Information
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Complete transition never called when view is starting to ...
Sometimes when some navigation action is dispatched (e.g. goBack() ) and then StackNavigator gets quickly unmounted COMPLETE_TRANSITION action ...
Read more >Component not unmounting when navigating between scenes
I am building a React Native component that listens for NetInfo changes and displays a modal dialog based on react-native-modal. This is the ......
Read more >Handling Mounting And Unmounting Of Navigation Routes In ...
In this article, we are going to walk through mounting and unmounting of navigation routes in React Native.
Read more >Troubleshooting | React Navigation
Sometimes you might have noticed that your screens unmount/remount, or your local component state or the navigation state resets when you navigate. This...
Read more >Tab components - React-Bootstrap
Defaults to <Fade> animation, else use false to disable or a react-transition-group <Transition/> component. unmountOnExit. boolean. Unmount the tab (remove it ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
While waiting for a fix, you can workaround this by adding
local
to the transition: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.
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.
https://stackblitz.com/edit/sveltejs-kit-template-default-8n1tyl?file=package.json,src%2Froutes%2F%2Blayout.svelte,src%2Froutes%2Fb%2F%2Blayout.svelte