mirror of https://github.com/sveltejs/svelte
Merge f77cebf37f into b4d1583ae2
commit
28877338bb
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: don't resurrect outroing elements when an ancestor block is paused and resumed
|
||||
@ -0,0 +1,23 @@
|
||||
import { flushSync } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
// #15604 — a removed each item mid-outro must not be resurrected by an ancestor pause/resume
|
||||
export default test({
|
||||
test({ assert, target, raf }) {
|
||||
const [remove, fetch] = target.querySelectorAll('button');
|
||||
|
||||
raf.tick(200);
|
||||
assert.equal(target.querySelectorAll('.item').length, 3);
|
||||
|
||||
flushSync(() => remove.click());
|
||||
|
||||
flushSync(() => fetch.click());
|
||||
raf.tick(30);
|
||||
|
||||
flushSync(() => fetch.click());
|
||||
raf.tick(2000);
|
||||
|
||||
const items = [...target.querySelectorAll('.item')].map((el) => el.textContent);
|
||||
assert.deepEqual(items, ['a', 'c']);
|
||||
}
|
||||
});
|
||||
@ -0,0 +1,19 @@
|
||||
<script>
|
||||
import { fade } from 'svelte/transition';
|
||||
|
||||
let fetching = $state(false);
|
||||
let items = $state(['a', 'b', 'c']);
|
||||
</script>
|
||||
|
||||
<button onclick={() => (items = items.filter((i) => i !== 'b'))}>remove</button>
|
||||
<button onclick={() => (fetching = !fetching)}>fetch</button>
|
||||
|
||||
{#if fetching}
|
||||
<p>loading</p>
|
||||
{:else}
|
||||
<div transition:fade={{ duration: 100 }}>
|
||||
{#each items as item (item)}
|
||||
<div class="item" transition:fade|global={{ duration: 100 }}>{item}</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
@ -0,0 +1,24 @@
|
||||
import { flushSync } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
// #15604 companion — flipping the condition back while the ancestor is paused must still revive the element
|
||||
export default test({
|
||||
test({ assert, target, raf }) {
|
||||
const [toggle, fetch] = target.querySelectorAll('button');
|
||||
|
||||
raf.tick(200);
|
||||
assert.ok(target.querySelector('.red'));
|
||||
|
||||
flushSync(() => toggle.click());
|
||||
|
||||
flushSync(() => fetch.click());
|
||||
raf.tick(30);
|
||||
|
||||
flushSync(() => toggle.click());
|
||||
|
||||
flushSync(() => fetch.click());
|
||||
raf.tick(2000);
|
||||
|
||||
assert.ok(target.querySelector('.red'));
|
||||
}
|
||||
});
|
||||
@ -0,0 +1,19 @@
|
||||
<script>
|
||||
import { fade } from 'svelte/transition';
|
||||
|
||||
let fetching = $state(false);
|
||||
let shown = $state(true);
|
||||
</script>
|
||||
|
||||
<button onclick={() => (shown = !shown)}>toggle</button>
|
||||
<button onclick={() => (fetching = !fetching)}>fetch</button>
|
||||
|
||||
{#if fetching}
|
||||
<p>loading</p>
|
||||
{:else}
|
||||
<div transition:fade={{ duration: 100 }}>
|
||||
{#if shown}
|
||||
<div class="red" transition:fade|global={{ duration: 100 }}>red</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
@ -0,0 +1,29 @@
|
||||
import { flushSync } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
// #15604 — an element mid-outro must not be resurrected when an ancestor
|
||||
// block is paused and resumed while the element's own condition is still false.
|
||||
// The outer `transition:fade` matters: it keeps the outer branch alive (pending
|
||||
// its own outro) so that toggling back takes the resume path
|
||||
export default test({
|
||||
test({ assert, target, raf }) {
|
||||
const [hide, fetch] = target.querySelectorAll('button');
|
||||
|
||||
// let the mount intro (dom variant) finish
|
||||
raf.tick(200);
|
||||
assert.ok(target.querySelector('.red'));
|
||||
|
||||
// start the outro of the inner block
|
||||
flushSync(() => hide.click());
|
||||
|
||||
// pause the outer block while the outro is in flight...
|
||||
flushSync(() => fetch.click());
|
||||
raf.tick(250);
|
||||
|
||||
// ...then resume it before either outro completes
|
||||
flushSync(() => fetch.click());
|
||||
raf.tick(2000);
|
||||
|
||||
assert.equal(target.querySelector('.red'), null);
|
||||
}
|
||||
});
|
||||
@ -0,0 +1,19 @@
|
||||
<script>
|
||||
import { fade } from 'svelte/transition';
|
||||
|
||||
let fetching = $state(false);
|
||||
let shown = $state(true);
|
||||
</script>
|
||||
|
||||
<button onclick={() => (shown = false)}>hide</button>
|
||||
<button onclick={() => (fetching = !fetching)}>fetch</button>
|
||||
|
||||
{#if fetching}
|
||||
<p>loading</p>
|
||||
{:else}
|
||||
<div transition:fade={{ duration: 100 }}>
|
||||
{#if shown}
|
||||
<div class="red" transition:fade|global={{ duration: 100 }}>red</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
Loading…
Reference in new issue