-
-
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
Svelte transition impacts navigation #628
Comments
I second this! Right now I have to avoid using transitions to keep navigation working. |
Solution to this in Vue: https://vuejs.org/v2/guide/transitions.html#Transition-Modes |
Ran into this earlier and only just figured out what it was! Definitely needs to be fixed. @thgh I think the specific answer to this problem is to actually not render transitions at all on route change. I don't need items in my list, for example, to fade out when I change the page - I just want them gone. |
Does |
Since this issue is still open, I can confirm that |
@romland @mustafa0x for me, I think there is an issue with routing and the tolerance of transitions, so I will be looking to see if there is a way to fix this when I have time (and brainpower). |
Just wanted to +1 this issue. Routing started acting funny as I was writing a back-end api. So I spent 2 hours trying to debug my async calls before finding this. |local stops components from sticking on navigation, but the animations glitch out. Oh well. |
After being stuck for the last few days on what the heck was going on, i found this thread and applied |local to all transitions and finally seems to have fixed my incorrectly destroyed pages. Be great to get this fixed at some point, ive run into it before too! |
@matt3224 are you using an old version of Sapper or Svelte? I'm fairly sure was fixed a few months ago now. |
Im using svelte 3.23.2 and 0.27.16 @antony i also thought this had been resolved. If i get time ill see if i can make a repro repo of it |
Still seeing this today with latest latest versions. I do my best to now use |local on everything unless that gives undesirable results i then use css transitions and class changes to get around it for now. Would be great to see this fixed once and for all! |
On a related note, I feel there's a good argument for making |
i do not know if this is the right place, but i have a similar error. I have a List Component with Child Elements like this: <IntersectionObserver let:intersecting>
{#if intersecting}
...
{#if $isMobileOnly}
....
{:else}
<List horizontal>
<div transition:page|local><Card href="/service" title="Service" /></div>
<div transition:page|local><Card href="/gallery" title="Gallery" /></div>
<div transition:page|local><Card href="/about" title="About" /></div>
{/if}
{/if}
</IntersectionObserver> When i add Is there any other way to fix this? Any ideas? |
HA! After three days of trying to find out what the heck is going on I came across this thread and guess what... exact same issue as the OP and applying A component from routeA showed up on routeB after using a href to go from routeA to routeB so all contents/components of routeB came in below the component from routeA 🤯 Of course I have a ton of That was four days ago... after peeling away one of those layers per day, trying to make sure it's not that thing, I'm here now, four layers deep into the rabbithole 🤣 The fifth layer of course was the browser cache, which I also made sure isn't the problem, that one was Endgegner on level ahm layer 2, which only took about 3 hours to defeat entirely and make sure no stone is left unturned... Well, For reference, all my package version below... it's up to date code so the issue still seems to be present these days: sa@m1-mini: ~/0/edm |master U:2 ✗| alias gr | gr svelte package.json
package.json:17: "@egjs/svelte-infinitegrid": "^3.0.4",
package.json:30: "@tsconfig/svelte": "^1.0.10",
package.json:52: "eslint-plugin-svelte3": "^2.7.3",
package.json:79: "rollup-plugin-svelte": "^7.0.0",
package.json:85: "svelte": "^3.30.0",
package.json:86: "svelte-check": "^1.1.17",
package.json:87: "svelte-click-outside": "^1.0.0",
package.json:88: "svelte-favicon-badge": "^1.0.0",
package.json:89: "svelte-forms-lib": "^1.2.2",
package.json:90: "svelte-grid": "^3.3.1",
package.json:91: "svelte-inline-input": "^1.2.1",
package.json:92: "svelte-preprocess": "^4.6.1",
package.json:93: "svelte-scrollto": "^0.2.0",
package.json:94: "svelte-spinner": "^2.0.2",
package.json:95: "svelte-typewriter": "^2.4.1",
package.json:135: "validate": "svelte-check"
sa@m1-mini: ~/0/edm |master U:2 ✗| gr \"sapper\" package.json
package.json:84: "sapper": "^0.28.10",
sa@m1-mini: ~/0/edm |master U:2 ✗| Found what was sending me in circles for the last few days... My // PageTransition.svelte
<script>
import { cubicInOut } from 'svelte/easing'
let duration = 250
let delay = duration
const transitionIn = () => ({
duration,
delay,
easing: cubicInOut,
css: (t) => `opacity: ${t}`,
})
const transitionOut = () => ({
duration,
delay: 0,
easing: cubicInOut,
css: (t) => `opacity: ${t}`,
})
</script>
<div in:transitionIn out:transitionOut|local>
<slot></slot>
</div> Adding |
I also encountered this issue with svelte kit but the |
Try this:
|
I think a lot of issues involving transitions (elements not being removed from the dom, transitions interfering with navigation, etc) could be mitigated if we had a way to trigger / abort a transition manually, and/or forcefully remove elements from the dom without having to wait for a transition to finish. I find myself battling with this often, especially when |
Ça serait bien d'avoir une solution plus systématique à sveltejs/kit#628
Ça serait bien d'avoir une solution plus systématique à sveltejs/kit#628
Ça serait bien d'avoir une solution plus systématique à sveltejs/kit#628
@evdama i'm finding that this no longer works in kit 202 i'm seeing the scroll to top flash before the next page fades in again like we used to get |
I was experiencing a similar problem as the one in the first post, reported by @imCorfitz. It turns out that the bug happens when the parent div to the |
@eduardoliron this is quite interesting, i actually use a position: relative as a css reset, i'll try setting to static and see if i can confirm your results |
I'm going to close this since transitions are working as intended (Svelte won't remove elements until transitions have completed), and |
For some reason If you care about keeping your (smooth) transition, I have a hack which I've tried and used. Though not the best of solutions, but it worked and it works. The root __layout.svelte <script lang="ts">
import { afterNavigate } from '$app/navigation';
afterNavigate(() => {
setTimeout(() => {
if (document?.querySelectorAll('body .App').length > 1) {
document?.body?.removeChild(document?.querySelector('body .App')!);
}
})
})
</script>
<main class="App">
Your App.
</main> Welcome. ⚡️ |
Why is |
Could we add a compile option for This issue keeps biting me. Most recently when "afterNavigate" was firing on a page that I just left, in spite of the fact that https://kit.svelte.dev/docs/modules#$app-navigation-afternavigate says it should unregister the handler when component unmounts. That part isn't wrong, it's just that the component was unmounted later than expected. Either that, or maybe someone should make a lint rule that all |
I agree with @janwillemtulp's suggestion: this should be the default. But @johnnysprinkles' suggestion to make it configurable is not bad either! Reasoning for us is basically we keep encountering "DOM-leaks" because a dev might forget to add a Because this issue is closed, question at @Rich-Harris regarding:
Is there by any chance a way to track or follow this topic, like is there a new issue registered? Or can we have a glimpse at considerations for Svelte v-next somewhere? |
This impacts me as well. There's a div that slides in and out but it looks weird when navigating away from the page. I would be happy with a modifier that specifies not to run transitions when navigating. E.g., I have nested blocks that are difficult to reorganize to make {#await load()}
loading...
{:then { a, b }}
{#if a}
<div>✅ Congrats.</div>
{:else if b}
<div class="b" transition:slide={{ easing: cubicIn, duration: 200 }}>
... ^^^^^^^^^^
</div>
{/if}
{/await} |
This is still an issue on main Sveltekit if anyone else got this nasty bug. Was debugging almost a-whole day. Would be nice to get warnings without using local, and to explicitly say |
I think this is the case in Svelte 4, which was released about a month ago. (https://svelte.dev/docs/v4-migration-guide#transitions-are-local-by-default) |
@FeldrinH looks like I'm still on 1? Vite is quiet behind then. |
SvelteKit and Svelte are two different packages. SvelteKit is a framework making use of Svelte. Could be interesting to see if indeed updating to the latest version of Svelte (not SvelteKit necessarily) could improve and/or fix this. |
Describe the bug
If a component used in a route has a transition applied, it will delay navigation and potentially create UI errors.
To Reproduce
In a brand new installation, create a new component e.g.
Linker.svelte
and include it in theindex
route.Moving the cursor on top of the link, a small picture will slowly fade in. Once clicking on the link, the image will slowly fade out again, but the
/about
page content will already be appended to the<slot />
and visible in the bottom. If the user moves the cursor back on top of the link while it is fading out, it will just fade in again and prevent the component from being removed completely - causing UI errors.Expected behavior
When navigating, default behaviour should be to just switch route. No delays nor attempts to finalise transitions or to show both routes in the
<slot />
at the same time.Information about your Sapper Installation:
Issue appears in both Chrome and Safari from what I have tested, but I expect this to be the same across all browsers.
Using iMac 2011 with OSX Mojave
Running in localhost
Current latest release v0.27.4
Svelte v3
dynamic application
Using Rollup
Severity
Mainly it is just annoying, and I can't really find a workaround to prevent it unless I just remove the transition from the image having it appear and disappear instantly.
Additional context
Maybe a modifier to the transition could be an idea. We currently have modifiers like
once
orpreventDefault
on click events. Maybe add atransition:fade|ignoreRoute={{duration: 200}}
or the quite opposite - having the developer purposely asking for route specific transition.The text was updated successfully, but these errors were encountered: