Skip to content

Commit 74742d9

Browse files
authored
fix: improve global transition outro handling (#10474)
1 parent d41d0c2 commit 74742d9

File tree

5 files changed

+50
-2
lines changed

5 files changed

+50
-2
lines changed

.changeset/gentle-dolls-juggle.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"svelte": patch
3+
---
4+
5+
fix: improve global transition outro handling

packages/svelte/src/internal/client/transitions.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,8 @@ function if_block_transition(transition) {
691691
transition.f(() => {
692692
const c = /** @type {Set<import('./types.js').Transition>} */ (consequent_transitions);
693693
c.delete(transition);
694-
if (c.size === 0) {
694+
// If the block has changed to falsy and has transitions
695+
if (!block.v && c.size === 0) {
695696
const consequent_effect = block.ce;
696697
execute_effect(/** @type {import('./types.js').EffectSignal} */ (consequent_effect));
697698
}
@@ -702,7 +703,8 @@ function if_block_transition(transition) {
702703
transition.f(() => {
703704
const a = /** @type {Set<import('./types.js').Transition>} */ (alternate_transitions);
704705
a.delete(transition);
705-
if (a.size === 0) {
706+
// If the block has changed to truthy and has transitions
707+
if (block.v && a.size === 0) {
706708
const alternate_effect = block.ae;
707709
execute_effect(/** @type {import('./types.js').EffectSignal} */ (alternate_effect));
708710
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<script>
2+
import { fade } from 'svelte/transition';
3+
let show = $state(true);
4+
</script>
5+
6+
<h1>Outside</h1>
7+
8+
{#if show}
9+
<button onclick={()=> show = false} transition:fade|global={{ duration: 100 }}>Hide</button>
10+
{/if}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { test } from '../../test';
2+
import { flushSync } from 'svelte';
3+
4+
export default test({
5+
async test({ assert, target, raf }) {
6+
const btn = target.querySelector('button');
7+
8+
raf.tick(0);
9+
10+
flushSync(() => {
11+
btn?.click();
12+
});
13+
14+
assert.htmlEqual(target.innerHTML, `<h1>Outside</h1><button>Hide</button>`);
15+
16+
raf.tick(100);
17+
18+
assert.htmlEqual(target.innerHTML, `<h1>Outside</h1>`);
19+
}
20+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<script>
2+
import Component from "./Component.svelte"
3+
let shown = $state(false);
4+
</script>
5+
6+
{#if shown}
7+
Nothing
8+
{:else}
9+
<svelte:component this={Component} />
10+
{/if}
11+

0 commit comments

Comments
 (0)