Skip to content

Commit

Permalink
feat: set transitions as local (#246)
Browse files Browse the repository at this point in the history
# Motivation

Svelte transitions are executed by default in components regardless if their parent components destroy those or not. This behavior is known as the `|global` transitions setting and is the default in Svelte v3.

This leads to issue with the SvelteKit navigation because DOM elements might not be detached and related context might remain active.

We generally notice the issue in NNS dapp after navigation when the DOM wrongly contains two `split-pane` elements.

In Svelte v4 the default behavior was changed to `|local`. Setting that can already be used in v3 when explicitely set. This setting has for effect to not execute the transition and destroy the components if parents destroy those. i.e. to populate the destroy.

# References

- documentation: https://svelte.dev/docs/v4-migration-guide#transitions-are-local-by-default
- svelte issue: sveltejs/svelte#6686

# Changes

- scope all transitions of Svelte to `|local`
  • Loading branch information
peterpeterparker committed Jul 12, 2023
1 parent e25312f commit 1eec2f4
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/lib/components/Backdrop.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
role="button"
tabindex="-1"
aria-label={$i18n.core.close}
in:fade={{ duration: FADE_IN_DURATION }}
out:fade={{ duration: FADE_OUT_DURATION }}
in:fade|local={{ duration: FADE_IN_DURATION }}
out:fade|local={{ duration: FADE_OUT_DURATION }}
class="backdrop"
on:click|stopPropagation={close}
on:keypress={($event) => handleKeyPress({ $event, callback: close })}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/BusyScreen.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<!-- Display spinner and lock UI if busyStore is not empty -->
{#if $busy}
<div data-tid="busy" transition:fade>
<div data-tid="busy" transition:fade|local>
<div class="content">
{#if nonNullish($busyMessage)}
<p>{$busyMessage}</p>
Expand Down
6 changes: 3 additions & 3 deletions src/lib/components/Modal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
{#if visible}
<div
class="modal"
transition:fade={{ duration: 25 }}
transition:fade|local={{ duration: 25 }}
on:introend
{role}
data-tid={testId}
Expand All @@ -45,8 +45,8 @@
>
<Backdrop {disablePointerEvents} on:nnsClose />
<div
in:fade={{ duration: FADE_IN_DURATION }}
out:fade={{ duration: FADE_OUT_DURATION }}
in:fade|local={{ duration: FADE_IN_DURATION }}
out:fade|local={{ duration: FADE_OUT_DURATION }}
class={`wrapper ${role}`}
>
{#if showHeader}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/Popover.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<div
role="menu"
aria-orientation="vertical"
transition:fade
transition:fade|local
class="popover"
tabindex="-1"
style="--popover-top: {`${bottom}px`}; --popover-left: {`${left}px`}; --popover-right: {`${
Expand All @@ -39,7 +39,7 @@
>
<Backdrop on:nnsClose={() => (visible = false)} />
<div
transition:scale={{ delay: 25, duration: 150, easing: quintOut }}
transition:scale|local={{ delay: 25, duration: 150, easing: quintOut }}
class="wrapper"
class:rtl={direction === "rtl"}
>
Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/Toast.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@
<div
role="dialog"
class={`toast ${theme ?? "themed"}`}
in:fly={{ y: (position === "top" ? -1 : 1) * 100, duration: 200 }}
out:fade={{ delay: 100 }}
in:fly|local={{ y: (position === "top" ? -1 : 1) * 100, duration: 200 }}
out:fade|local={{ delay: 100 }}
>
<div class="icon {level}" aria-hidden="true">
{#if spinner}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/WizardTransition.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
{#key transition}
<div
bind:clientWidth={absolutOffset}
in:fly={{ x: slideOffset, duration: ANIMATION_DURATION }}
in:fly|local={{ x: slideOffset, duration: ANIMATION_DURATION }}
>
<slot />
</div>
Expand Down

0 comments on commit 1eec2f4

Please sign in to comment.