question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Svelte transition impacts navigation

See original GitHub issue

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 the index route.

<!-- src/lib/Linker.svelte -->
<script>
  import { fade } from "svelte/transition";
  let showImage = false;
</script>

<div
  on:mouseenter={() => {
    showImage = true;
  }}
  on:mouseleave={() => {
    showImage = false;
  }}>

  <h1>Wow hi!</h1>
  <a href="/about">About</a>
  {#if showImage}
    <img
      transition:fade={{ duration: 2000 }}
      src="https://picsum.photos/20"
      alt="" />
  {/if}
</div>
<!-- src/routes/index.svelte -->
<script>
  import Linker from "../lib/Linker.svelte";
</script>

...

<Linker />
<h1>Great success!</h1>

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.

ezgif-4-99f035a10dee

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 or preventDefault on click events. Maybe add a transition:fade|ignoreRoute={{duration: 200}} or the quite opposite - having the developer purposely asking for route specific transition.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:48
  • Comments:26 (6 by maintainers)

github_iconTop GitHub Comments

71reactions
mustafa0xcommented, Oct 29, 2019
10reactions
janwillemtulpcommented, Aug 19, 2022

I’m going to close this since transitions are working as intended (Svelte won’t remove elements until transitions have completed), and |local is the way to get the desired outcome. I do acknowledge that some behaviour around transitions is a little counterintuitive though — it’s on our list of things to revisit for Svelte 4, when we have the opportunity to make breaking changes.

Why is |local not the default behaviour and then you have to set the opposite, if desired (wait until something else is complete)?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Svelte Smooth page transitions - DEV Community ‍ ‍
Create Svelte Transitions that are. ... If you refresh your browser and navigate from page to page you should see the flickering effect....
Read more >
Transitions / Custom CSS transitions • Svelte Tutorial
The svelte/transition module has a handful of built-in transitions, but it's very easy to create your own. By way of example, this is...
Read more >
Native Page Transitions in SvelteKit: Part 1 - Geoff Rich
When a single-page app navigation is about to take place, we call document.createDocumentTransition() to create the page transition. We then ...
Read more >
Problem with routing and transitions : r/sveltejs - Reddit
If I navigate in the middle of a transition the routing seems to wait for ... 'svelte' import { fade } from 'svelte/transitions'...
Read more >
Svelte transition between two elements "jumps" - Stack Overflow
A few tweaks to the CSS to ensure there are no strange side-effects (a container set to position: relative, and setting width of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found