mirror of https://github.com/sveltejs/svelte
commit
7573848a9e
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: leave stale promises to wait for a later resolution, instead of rejecting
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: reapply context after transforming error during SSR
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: don't rebase just-created batches
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
chore: allow `null` for `pending` in typings
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: flush eager effects in production
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: rethrow error of failed iterable after calling `return()`
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: resolve stale deriveds with latest value
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
chore: remove unnecessary `increment_pending` calls
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: correctly compile component member expressions for SSR
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: reset `source.updated` stack traces after `flush`
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"svelte": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: replacing async 'blocking' strategy with 'merging'
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: abort running obsolete async branches
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: wrap `Promise.all` in `save` during SSR
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: ignore false-positive errors of `$inspect` dependencies
|
||||||
@ -0,0 +1,23 @@
|
|||||||
|
import { tick } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
async test({ assert, target }) {
|
||||||
|
await tick();
|
||||||
|
const [increment, shift] = target.querySelectorAll('button');
|
||||||
|
|
||||||
|
increment.click();
|
||||||
|
await tick();
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`<button>clicks: 0 - 0 - 0</button> <button>shift</button> <p>true - true</p>`
|
||||||
|
);
|
||||||
|
|
||||||
|
shift.click();
|
||||||
|
await tick();
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`<button>clicks: 1 - 1 - 1</button> <button>shift</button> <p>false - false</p>`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
@ -0,0 +1,22 @@
|
|||||||
|
<script>
|
||||||
|
|
||||||
|
let count = $state(0);
|
||||||
|
const delayedCount = $derived(await push(count));
|
||||||
|
const derivedCount = $derived(count);
|
||||||
|
|
||||||
|
let resolvers = [];
|
||||||
|
|
||||||
|
function push(value) {
|
||||||
|
if (!value) return value;
|
||||||
|
const { promise, resolve } = Promise.withResolvers();
|
||||||
|
resolvers.push(() => resolve(value));
|
||||||
|
return promise;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button onclick={() => count += 1}>
|
||||||
|
clicks: {count} - {delayedCount} - {derivedCount}
|
||||||
|
</button>
|
||||||
|
<button onclick={() => resolvers.shift()?.()}>shift</button>
|
||||||
|
|
||||||
|
<p>{$state.eager(count) !== count} - {$state.eager(derivedCount) !== derivedCount}</p>
|
||||||
@ -0,0 +1,30 @@
|
|||||||
|
import { tick } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
async test({ assert, target }) {
|
||||||
|
await tick();
|
||||||
|
const [increment, shift, middle] = target.querySelectorAll('button');
|
||||||
|
const [div] = target.querySelectorAll('div');
|
||||||
|
|
||||||
|
increment.click();
|
||||||
|
await tick();
|
||||||
|
increment.click();
|
||||||
|
await tick();
|
||||||
|
increment.click();
|
||||||
|
await tick();
|
||||||
|
middle.click(); // resolve the second increment which will make the if block go away and the first batch discarded
|
||||||
|
await tick();
|
||||||
|
assert.htmlEqual(div.innerHTML, '2 2');
|
||||||
|
|
||||||
|
shift.click();
|
||||||
|
await tick();
|
||||||
|
shift.click();
|
||||||
|
await tick();
|
||||||
|
shift.click();
|
||||||
|
await tick();
|
||||||
|
shift.click();
|
||||||
|
await tick();
|
||||||
|
assert.htmlEqual(div.innerHTML, '3 3');
|
||||||
|
}
|
||||||
|
});
|
||||||
@ -0,0 +1,21 @@
|
|||||||
|
<script>
|
||||||
|
let a = $state(0);
|
||||||
|
|
||||||
|
const deferred = [];
|
||||||
|
|
||||||
|
function delay(value) {
|
||||||
|
if (!value) return value;
|
||||||
|
return new Promise((resolve) => deferred.push(() => resolve(value)));
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
{a} {await delay(a)}
|
||||||
|
{#if a < 2}
|
||||||
|
{await delay(a)}
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button onclick={() => {a++;}}>a++</button>
|
||||||
|
<button onclick={() => deferred.shift()?.()}>shift</button>
|
||||||
|
<button onclick={() => deferred[2]()}>middle</button>
|
||||||
@ -0,0 +1,19 @@
|
|||||||
|
import { tick } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
// Tests that batch.#commit() does not null out a potentially new current_batch
|
||||||
|
export default test({
|
||||||
|
skip_initial_flushSync: true, // test that the initial batch is flushed without an explicit flushSync() call
|
||||||
|
async test({ assert, target }) {
|
||||||
|
await tick();
|
||||||
|
|
||||||
|
const [button] = target.querySelectorAll('button');
|
||||||
|
const [updates] = target.querySelectorAll('p');
|
||||||
|
|
||||||
|
assert.htmlEqual(updates.innerHTML, 'false');
|
||||||
|
|
||||||
|
button.click();
|
||||||
|
await tick();
|
||||||
|
assert.htmlEqual(updates.innerHTML, 'true');
|
||||||
|
}
|
||||||
|
});
|
||||||
@ -0,0 +1,30 @@
|
|||||||
|
<script>
|
||||||
|
let count = $state(-1);
|
||||||
|
let payload = $state(false);
|
||||||
|
let updated = $state(false);
|
||||||
|
|
||||||
|
$effect(() => {
|
||||||
|
if (payload) {
|
||||||
|
updated = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function update() {
|
||||||
|
count = 0;
|
||||||
|
queueMicrotask(() => {
|
||||||
|
payload = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button onclick={update}>update</button>
|
||||||
|
|
||||||
|
<p>{updated}</p>
|
||||||
|
|
||||||
|
<svelte:boundary>
|
||||||
|
{await new Promise(() => {})}
|
||||||
|
|
||||||
|
{#snippet pending()}
|
||||||
|
<p>pending</p>
|
||||||
|
{/snippet}
|
||||||
|
</svelte:boundary>
|
||||||
@ -0,0 +1,27 @@
|
|||||||
|
import { tick } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
// Tests that a newly created batch during an effect flush isn't rebased right away by the previous batch.#commit(),
|
||||||
|
// rescheduling an effect on the new batch that shouldn't run.
|
||||||
|
export default test({
|
||||||
|
async test({ assert, target, logs }) {
|
||||||
|
await tick();
|
||||||
|
const [increment, resolve] = target.querySelectorAll('button');
|
||||||
|
|
||||||
|
increment.click();
|
||||||
|
await tick();
|
||||||
|
assert.deepEqual(logs, []);
|
||||||
|
|
||||||
|
// This resolve
|
||||||
|
// - shouldn't result in the derived execution capturing the new derived value on the new batch, but on the previous batch which is currently flushing
|
||||||
|
// - shouldn't result in #commit() rebasing the new batch
|
||||||
|
resolve.click();
|
||||||
|
await tick();
|
||||||
|
assert.deepEqual(logs, [2]);
|
||||||
|
|
||||||
|
// As a result, this resolve shouldn't result in another execution of the effect depending on the derived
|
||||||
|
resolve.click();
|
||||||
|
await tick();
|
||||||
|
assert.deepEqual(logs, [2]);
|
||||||
|
}
|
||||||
|
});
|
||||||
@ -0,0 +1,32 @@
|
|||||||
|
<script>
|
||||||
|
let count = $state(0);
|
||||||
|
let double = $derived(count * 2);
|
||||||
|
let count_mirror = $state(0);
|
||||||
|
|
||||||
|
const queued = [];
|
||||||
|
function delay(v) {
|
||||||
|
if (!v) return v;
|
||||||
|
return new Promise(resolve => {
|
||||||
|
queued.push(() => resolve(v));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button onclick={() => count++}>count {await delay(count)} | count_mirror {await delay(count_mirror)}</button>
|
||||||
|
<button onclick={() => queued.shift()?.()}>resolve</button>
|
||||||
|
|
||||||
|
{#if count}
|
||||||
|
<!-- inside if block so effects are newly created and therefore added to batch.#new_effects -->
|
||||||
|
<!-- first $effect creates new batch ... -->
|
||||||
|
{(() => {
|
||||||
|
$effect(() => {
|
||||||
|
count_mirror = count;
|
||||||
|
})
|
||||||
|
})()}
|
||||||
|
<!-- ... which second $effect shouldn't write to because the derived execution belongs to the previous batch -->
|
||||||
|
{(() => {
|
||||||
|
$effect(() => {
|
||||||
|
console.log(double);
|
||||||
|
})
|
||||||
|
})()}
|
||||||
|
{/if}
|
||||||
@ -0,0 +1,25 @@
|
|||||||
|
import { tick } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
// Tests that a newly created batch during an effect flush isn't rebased right away by the previous batch.#commit(),
|
||||||
|
// rescheduling an effect on the new batch that shouldn't run.
|
||||||
|
export default test({
|
||||||
|
async test({ assert, target, logs }) {
|
||||||
|
await tick();
|
||||||
|
const [increment, resolve] = target.querySelectorAll('button');
|
||||||
|
assert.deepEqual(logs, ['delay 0']);
|
||||||
|
|
||||||
|
increment.click();
|
||||||
|
await tick();
|
||||||
|
assert.deepEqual(logs, ['delay 0', 'delay 2']);
|
||||||
|
|
||||||
|
// This resolve should trigger the async effect only once
|
||||||
|
resolve.click();
|
||||||
|
await tick();
|
||||||
|
assert.deepEqual(logs, ['delay 0', 'delay 2', 'effect run', 'delay 4']);
|
||||||
|
|
||||||
|
resolve.click();
|
||||||
|
await tick();
|
||||||
|
assert.deepEqual(logs, ['delay 0', 'delay 2', 'effect run', 'delay 4']);
|
||||||
|
}
|
||||||
|
});
|
||||||
@ -0,0 +1,29 @@
|
|||||||
|
<script>
|
||||||
|
import { untrack } from "svelte";
|
||||||
|
|
||||||
|
let a = $state(0);
|
||||||
|
let b = $state(0);
|
||||||
|
let c = $state(0);
|
||||||
|
|
||||||
|
const queued = [];
|
||||||
|
function delay(v) {
|
||||||
|
console.log('delay ' + v);
|
||||||
|
if (!v) return v;
|
||||||
|
return new Promise(resolve => {
|
||||||
|
queued.push(() => resolve(v));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
$effect(() => {
|
||||||
|
if (b + c === 0 || b + c > 2) return;
|
||||||
|
console.log('effect run')
|
||||||
|
untrack(() => {
|
||||||
|
b++;
|
||||||
|
c++;
|
||||||
|
})
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button onclick={() => { a++; b++; }}>increment</button>
|
||||||
|
<button onclick={() => queued.shift()?.()}>resolve</button>
|
||||||
|
{await delay(a + b + c)}
|
||||||
@ -0,0 +1,31 @@
|
|||||||
|
import { tick } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
// Tests that a newly created batch during an effect flush isn't rebased right away by the previous batch.#commit(),
|
||||||
|
// rescheduling an effect on the new batch that shouldn't run.
|
||||||
|
export default test({
|
||||||
|
async test({ assert, target, logs }) {
|
||||||
|
await tick();
|
||||||
|
const [increment, shift, pop] = target.querySelectorAll('button');
|
||||||
|
|
||||||
|
increment.click();
|
||||||
|
await tick();
|
||||||
|
assert.deepEqual(logs, []);
|
||||||
|
|
||||||
|
// Resolve the blocking await which shouldn't result in the derived execution capturing
|
||||||
|
// the new derived value on the new batch, but on the previous batch which is currently flushing
|
||||||
|
pop.click();
|
||||||
|
await tick();
|
||||||
|
assert.deepEqual(logs, [2]);
|
||||||
|
|
||||||
|
// Resolve the non-blocking await which shouldn't result in #commit() rebasing the new batch
|
||||||
|
shift.click();
|
||||||
|
await tick();
|
||||||
|
assert.deepEqual(logs, [2]);
|
||||||
|
|
||||||
|
// Resolve the new batch's await
|
||||||
|
shift.click();
|
||||||
|
await tick();
|
||||||
|
assert.deepEqual(logs, [2]);
|
||||||
|
}
|
||||||
|
});
|
||||||
@ -0,0 +1,37 @@
|
|||||||
|
<script>
|
||||||
|
let count = $state(0);
|
||||||
|
let double = $derived(count * 2);
|
||||||
|
let count_mirror = $state(0);
|
||||||
|
|
||||||
|
const queued = [];
|
||||||
|
function delay(v) {
|
||||||
|
if (!v) return v;
|
||||||
|
return new Promise(resolve => {
|
||||||
|
queued.push(() => resolve(v));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button onclick={() => count++}>count {await delay(count)} | count_mirror {await delay(count_mirror)}</button>
|
||||||
|
<button onclick={() => queued.shift()?.()}>shift</button>
|
||||||
|
<button onclick={() => queued.pop()?.()}>pop</button>
|
||||||
|
|
||||||
|
{#if count}
|
||||||
|
<svelte:boundary>
|
||||||
|
{await delay(count)}
|
||||||
|
{#snippet pending()}loading{/snippet}
|
||||||
|
</svelte:boundary>
|
||||||
|
<!-- inside if block so effects are newly created and therefore added to batch.#new_effects -->
|
||||||
|
<!-- first $effect creates new batch ... -->
|
||||||
|
{(() => {
|
||||||
|
$effect(() => {
|
||||||
|
count_mirror = count;
|
||||||
|
})
|
||||||
|
})()}
|
||||||
|
<!-- ... which second $effect shouldn't write to because the derived execution belongs to the previous batch -->
|
||||||
|
{(() => {
|
||||||
|
$effect(() => {
|
||||||
|
console.log(double);
|
||||||
|
})
|
||||||
|
})()}
|
||||||
|
{/if}
|
||||||
@ -0,0 +1,58 @@
|
|||||||
|
import { tick } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
// Tests that a newly created batch during an effect flush isn't rebased right away by the previous batch.#commit(),
|
||||||
|
// rescheduling an effect on the new batch that shouldn't run.
|
||||||
|
export default test({
|
||||||
|
async test({ assert, target, logs }) {
|
||||||
|
await tick();
|
||||||
|
const [increment, unrelated, resolve] = target.querySelectorAll('button');
|
||||||
|
|
||||||
|
increment.click();
|
||||||
|
await tick();
|
||||||
|
assert.deepEqual(logs, []);
|
||||||
|
|
||||||
|
// This resolve
|
||||||
|
// - shouldn't result in the derived execution capturing the new derived value on the new batch, but on the previous batch which is currently flushing
|
||||||
|
// - shouldn't result in #commit() rebasing the new batch
|
||||||
|
resolve.click();
|
||||||
|
await tick();
|
||||||
|
assert.deepEqual(logs, [2]);
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`
|
||||||
|
<button>count 1 | count_mirror 0 | count_mirror_d 0 | unrelated 0</button>
|
||||||
|
<button>unrelated++</button>
|
||||||
|
<button>resolve</button>
|
||||||
|
`
|
||||||
|
);
|
||||||
|
|
||||||
|
// This resolve
|
||||||
|
// - shouldn't result in the derived execution capturing the new derived value on the new batch, but on the previous batch which is currently flushing
|
||||||
|
// - shouldn't result in #commit() rebasing the new batch
|
||||||
|
unrelated.click();
|
||||||
|
await tick();
|
||||||
|
assert.deepEqual(logs, [2]);
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`
|
||||||
|
<button>count 1 | count_mirror 0 | count_mirror_d 0 | unrelated 1</button>
|
||||||
|
<button>unrelated++</button>
|
||||||
|
<button>resolve</button>
|
||||||
|
`
|
||||||
|
);
|
||||||
|
|
||||||
|
// As a result, this resolve shouldn't result in another execution of the effect depending on the derived
|
||||||
|
resolve.click();
|
||||||
|
await tick();
|
||||||
|
assert.deepEqual(logs, [2]);
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`
|
||||||
|
<button>count 1 | count_mirror 1 | count_mirror_d 2 | unrelated 1</button>
|
||||||
|
<button>unrelated++</button>
|
||||||
|
<button>resolve</button>
|
||||||
|
`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
@ -0,0 +1,38 @@
|
|||||||
|
<script>
|
||||||
|
import { untrack } from "svelte";
|
||||||
|
|
||||||
|
let count = $state(0);
|
||||||
|
let double = $derived(count * 2);
|
||||||
|
let count_mirror = $state(0);
|
||||||
|
let unrelated = $state(0);
|
||||||
|
let count_mirror_d = $derived(count_mirror * 2);
|
||||||
|
|
||||||
|
const queued = [];
|
||||||
|
function delay(v) {
|
||||||
|
if (!v) return v;
|
||||||
|
return new Promise(resolve => {
|
||||||
|
queued.push(() => resolve(v));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button onclick={() => count++}>count {await delay(count)} | count_mirror {await delay(count_mirror)} | count_mirror_d {count_mirror_d} | unrelated {unrelated}</button>
|
||||||
|
<button onclick={() => unrelated++}>unrelated++</button>
|
||||||
|
<button onclick={() => queued.shift()?.()}>resolve</button>
|
||||||
|
|
||||||
|
{#if count}
|
||||||
|
<!-- inside if block so effects are newly created and therefore added to batch.#new_effects -->
|
||||||
|
<!-- first $effect creates new batch ... -->
|
||||||
|
{(() => {
|
||||||
|
$effect(() => {
|
||||||
|
count_mirror = count;
|
||||||
|
untrack(() => count_mirror_d); // execute derived; should associate value with the right batch
|
||||||
|
})
|
||||||
|
})()}
|
||||||
|
<!-- ... which second $effect shouldn't write to because the derived execution belongs to the previous batch -->
|
||||||
|
{(() => {
|
||||||
|
$effect(() => {
|
||||||
|
console.log(double);
|
||||||
|
})
|
||||||
|
})()}
|
||||||
|
{/if}
|
||||||
@ -0,0 +1,25 @@
|
|||||||
|
import { tick } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
async test({ assert, target }) {
|
||||||
|
await tick();
|
||||||
|
|
||||||
|
const [increment, shift] = target.querySelectorAll('button');
|
||||||
|
|
||||||
|
increment.click();
|
||||||
|
await tick();
|
||||||
|
|
||||||
|
assert.htmlEqual(target.innerHTML, '<button>clicks: 0</button><button>shift</button> 0');
|
||||||
|
|
||||||
|
shift.click();
|
||||||
|
await tick();
|
||||||
|
|
||||||
|
assert.htmlEqual(target.innerHTML, '<button>clicks: 1</button><button>shift</button> 1');
|
||||||
|
|
||||||
|
shift.click();
|
||||||
|
await tick();
|
||||||
|
|
||||||
|
assert.htmlEqual(target.innerHTML, '<button>clicks: 2</button><button>shift</button> 2');
|
||||||
|
}
|
||||||
|
});
|
||||||
@ -0,0 +1,25 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { flushSync } from 'svelte';
|
||||||
|
|
||||||
|
let count = $state(0);
|
||||||
|
|
||||||
|
const queue: Array<() => void> = [];
|
||||||
|
|
||||||
|
$effect(() => {
|
||||||
|
if (count === 1) {
|
||||||
|
count = 2;
|
||||||
|
flushSync();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
function push(v: number) {
|
||||||
|
if (v === 0) return v;
|
||||||
|
return new Promise(r => queue.push(() => r(v)));
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button onclick={() => count += 1}>
|
||||||
|
clicks: {count}
|
||||||
|
</button>
|
||||||
|
<button onclick={() => queue.shift()?.()}>shift</button>
|
||||||
|
{await push(count)}
|
||||||
@ -0,0 +1,20 @@
|
|||||||
|
import { tick } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
async test({ assert, target }) {
|
||||||
|
const [increment, pop] = target.querySelectorAll('button');
|
||||||
|
|
||||||
|
increment.click();
|
||||||
|
await tick();
|
||||||
|
increment.click();
|
||||||
|
await tick();
|
||||||
|
pop.click();
|
||||||
|
await tick();
|
||||||
|
assert.htmlEqual(target.innerHTML, `<button>increment</button> <button>pop</button> 2 2 1`);
|
||||||
|
|
||||||
|
pop.click();
|
||||||
|
await tick();
|
||||||
|
assert.htmlEqual(target.innerHTML, `<button>increment</button> <button>pop</button> 2 2 1`);
|
||||||
|
}
|
||||||
|
});
|
||||||
@ -0,0 +1,26 @@
|
|||||||
|
<script>
|
||||||
|
let count = $state(0);
|
||||||
|
let other = $state(0);
|
||||||
|
|
||||||
|
const queue = [];
|
||||||
|
function push(v) {
|
||||||
|
return new Promise((r,e) => queue.push(() => v === 1 ? e(v) : r(v)));
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button onclick={() => {
|
||||||
|
if (count === 0) {
|
||||||
|
other++;
|
||||||
|
count++;
|
||||||
|
} else {
|
||||||
|
count++
|
||||||
|
}
|
||||||
|
}}>increment</button>
|
||||||
|
<button onclick={() => queue.pop()?.()}>pop</button>
|
||||||
|
|
||||||
|
{#if count > 0}
|
||||||
|
<svelte:boundary>
|
||||||
|
{await push(count)} {count} {other}
|
||||||
|
{#snippet failed()}boom{/snippet}
|
||||||
|
</svelte:boundary>
|
||||||
|
{/if}
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
<script>
|
||||||
|
let { count } = $props();
|
||||||
|
let double = $derived(count * 2);
|
||||||
|
|
||||||
|
$effect.pre(() => console.log(count, double));
|
||||||
|
</script>
|
||||||
@ -0,0 +1,27 @@
|
|||||||
|
import { tick } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
async test({ assert, target, logs, warnings }) {
|
||||||
|
const [increment, resolve] = target.querySelectorAll('button');
|
||||||
|
|
||||||
|
increment.click();
|
||||||
|
await tick();
|
||||||
|
assert.deepEqual(logs, []);
|
||||||
|
|
||||||
|
resolve.click();
|
||||||
|
await tick();
|
||||||
|
assert.deepEqual(logs, []);
|
||||||
|
|
||||||
|
resolve.click();
|
||||||
|
await tick();
|
||||||
|
assert.deepEqual(logs, []);
|
||||||
|
|
||||||
|
resolve.click();
|
||||||
|
await tick();
|
||||||
|
assert.deepEqual(logs, [1, 2]);
|
||||||
|
|
||||||
|
// no await waterfall / inert derived warnings
|
||||||
|
assert.deepEqual(warnings, []);
|
||||||
|
}
|
||||||
|
});
|
||||||
@ -0,0 +1,31 @@
|
|||||||
|
<script>
|
||||||
|
import Child from "./Child.svelte";
|
||||||
|
let count = $state(0);
|
||||||
|
|
||||||
|
let deferreds = [];
|
||||||
|
|
||||||
|
function push(v) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
deferreds.push({ resolve: () => resolve(v), reject });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button onclick={() => count += 1}>increment</button>
|
||||||
|
<button onclick={() => deferreds.shift()?.resolve()}>resolve</button>
|
||||||
|
|
||||||
|
<svelte:boundary>
|
||||||
|
{#if count % 2 === 0}
|
||||||
|
{@const double = count * 2}
|
||||||
|
<p>true</p>
|
||||||
|
{await push(count)} {double}
|
||||||
|
<Child count={await push(count)} />
|
||||||
|
{:else}
|
||||||
|
<p>false</p>
|
||||||
|
<Child count={await push(count)} />
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#snippet pending()}
|
||||||
|
<p>loading...</p>
|
||||||
|
{/snippet}
|
||||||
|
</svelte:boundary>
|
||||||
@ -0,0 +1,24 @@
|
|||||||
|
import { tick } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
import { normalise_trace_logs } from '../../../helpers.js';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
compileOptions: {
|
||||||
|
dev: true
|
||||||
|
},
|
||||||
|
html: '<p>pending</p>',
|
||||||
|
async test({ assert, target, warnings }) {
|
||||||
|
await tick();
|
||||||
|
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
'<h1>number -> number -> number -> return -> body failed -> ended</h1>'
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.deepEqual(normalise_trace_logs(warnings), [
|
||||||
|
{
|
||||||
|
log: 'Detected reactivity loss when reading `values[1]`. This happens when state is read in an async function after an earlier `await`'
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
});
|
||||||
@ -0,0 +1,45 @@
|
|||||||
|
<script>
|
||||||
|
let values = $state([0, 1, 2]);
|
||||||
|
|
||||||
|
async function get_result() {
|
||||||
|
const logs = [];
|
||||||
|
|
||||||
|
const iterator = {
|
||||||
|
index: 0,
|
||||||
|
async next() {
|
||||||
|
if (this.index > 2) { done: true }
|
||||||
|
return { done: false, value: values[this.index++] };
|
||||||
|
},
|
||||||
|
async return() {
|
||||||
|
logs.push('return');
|
||||||
|
},
|
||||||
|
[Symbol.asyncIterator]() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
for await (const value of iterator) {
|
||||||
|
logs.push('number');
|
||||||
|
// Read reactive state after async iterator await.
|
||||||
|
if (values.length === 3 && value === 2) {
|
||||||
|
throw new Error('body failed');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
logs.push('done');
|
||||||
|
} catch (error) {
|
||||||
|
logs.push(error.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
logs.push('ended');
|
||||||
|
return logs.join(' -> ');
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<svelte:boundary>
|
||||||
|
<h1>{await get_result()}</h1>
|
||||||
|
|
||||||
|
{#snippet pending()}
|
||||||
|
<p>pending</p>
|
||||||
|
{/snippet}
|
||||||
|
</svelte:boundary>
|
||||||
@ -0,0 +1,21 @@
|
|||||||
|
import { tick } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
import { normalise_trace_logs } from '../../../helpers.js';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
compileOptions: {
|
||||||
|
dev: true
|
||||||
|
},
|
||||||
|
html: '<p>pending</p>',
|
||||||
|
async test({ assert, target, warnings }) {
|
||||||
|
await tick();
|
||||||
|
|
||||||
|
assert.htmlEqual(target.innerHTML, '<h1>number -> number -> next failed -> ended</h1>');
|
||||||
|
|
||||||
|
assert.deepEqual(normalise_trace_logs(warnings), [
|
||||||
|
{
|
||||||
|
log: 'Detected reactivity loss when reading `values[1]`. This happens when state is read in an async function after an earlier `await`'
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
});
|
||||||
@ -0,0 +1,43 @@
|
|||||||
|
<script>
|
||||||
|
let values = $state([0, 1, 2]);
|
||||||
|
|
||||||
|
async function get_result() {
|
||||||
|
const logs = [];
|
||||||
|
|
||||||
|
const iterator = {
|
||||||
|
index: 0,
|
||||||
|
async next() {
|
||||||
|
if (this.index > 1) throw new Error('next failed');
|
||||||
|
return { done: false, value: values[this.index++] };
|
||||||
|
},
|
||||||
|
async return() {
|
||||||
|
logs.push('return');
|
||||||
|
},
|
||||||
|
[Symbol.asyncIterator]() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
for await (const value of iterator) {
|
||||||
|
logs.push('number');
|
||||||
|
// Read reactive state after async iterator await.
|
||||||
|
values.length === value;
|
||||||
|
}
|
||||||
|
logs.push('done');
|
||||||
|
} catch (error) {
|
||||||
|
logs.push(error.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
logs.push('ended');
|
||||||
|
return logs.join(' -> ');
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<svelte:boundary>
|
||||||
|
<h1>{await get_result()}</h1>
|
||||||
|
|
||||||
|
{#snippet pending()}
|
||||||
|
<p>pending</p>
|
||||||
|
{/snippet}
|
||||||
|
</svelte:boundary>
|
||||||
@ -0,0 +1,29 @@
|
|||||||
|
import { tick } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
async test({ assert, target }) {
|
||||||
|
await tick();
|
||||||
|
|
||||||
|
const [increment, pop] = target.querySelectorAll('button');
|
||||||
|
|
||||||
|
increment.click();
|
||||||
|
await tick();
|
||||||
|
|
||||||
|
increment.click();
|
||||||
|
await tick();
|
||||||
|
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`<button>increment</button><button>pop</button><p>0 0 0</p>`
|
||||||
|
);
|
||||||
|
|
||||||
|
pop.click();
|
||||||
|
await tick();
|
||||||
|
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`<button>increment</button><button>pop</button><p>2 2 1</p>`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
@ -0,0 +1,22 @@
|
|||||||
|
<script>
|
||||||
|
let count = $state(0);
|
||||||
|
let other = $state(0);
|
||||||
|
|
||||||
|
const queue = [];
|
||||||
|
|
||||||
|
function push(v) {
|
||||||
|
if (v === 0) return v;
|
||||||
|
|
||||||
|
return new Promise((fulfil) => {
|
||||||
|
queue.push(() => fulfil(v));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button onclick={() => {
|
||||||
|
if (count === 0) other++;
|
||||||
|
count++;
|
||||||
|
}}>increment</button>
|
||||||
|
<button onclick={() => queue.pop()?.()}>pop</button>
|
||||||
|
|
||||||
|
<p>{await push(count)} {count} {other}</p>
|
||||||
@ -0,0 +1,28 @@
|
|||||||
|
import { tick } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
async test({ assert, target }) {
|
||||||
|
await tick();
|
||||||
|
|
||||||
|
const [increment, hide, pop] = target.querySelectorAll('button');
|
||||||
|
|
||||||
|
increment.click();
|
||||||
|
await tick();
|
||||||
|
pop.click();
|
||||||
|
await tick();
|
||||||
|
hide.click(); // hides the if block, which cancels the pending async inside, which means the batch can complete
|
||||||
|
await tick();
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`<button>increment</button> <button>hide</button> <button>pop</button> 1`
|
||||||
|
);
|
||||||
|
|
||||||
|
pop.click();
|
||||||
|
await tick();
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`<button>increment</button> <button>hide</button> <button>pop</button> 1`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
@ -0,0 +1,21 @@
|
|||||||
|
<script>
|
||||||
|
let show = $state(true);
|
||||||
|
let count = $state(0);
|
||||||
|
|
||||||
|
const queue = [];
|
||||||
|
|
||||||
|
function push(value) {
|
||||||
|
if (!value) return value;
|
||||||
|
return new Promise(r => queue.push(() => r(value)));
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button onclick={() => count += 1}>increment</button>
|
||||||
|
<button onclick={() => show = false}>hide</button>
|
||||||
|
<!-- pop() so that the outer one resolves first, not the one inside the if block -->
|
||||||
|
<button onclick={() => queue.pop()?.()}>pop</button>
|
||||||
|
|
||||||
|
{await push(count)}
|
||||||
|
{#if show}
|
||||||
|
{await push(count)}
|
||||||
|
{/if}
|
||||||
@ -0,0 +1,33 @@
|
|||||||
|
import { tick } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
async test({ assert, target }) {
|
||||||
|
await tick();
|
||||||
|
|
||||||
|
const [increment, shift] = target.querySelectorAll('button');
|
||||||
|
|
||||||
|
increment.click();
|
||||||
|
await tick();
|
||||||
|
increment.click();
|
||||||
|
await tick();
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`<button>3</button><button>shift</button><p>1 = 1</p><p>fizz: true</p><p>buzz: true</p>`
|
||||||
|
);
|
||||||
|
|
||||||
|
shift.click();
|
||||||
|
await tick();
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`<button>3</button><button>shift</button><p>1 = 1</p><p>fizz: true</p><p>buzz: true</p>`
|
||||||
|
);
|
||||||
|
|
||||||
|
shift.click();
|
||||||
|
await tick();
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`<button>3</button><button>shift</button><p>3 = 3</p><p>fizz: true</p><p>buzz: false</p>`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
@ -0,0 +1,44 @@
|
|||||||
|
<script>
|
||||||
|
import { getAbortSignal } from 'svelte';
|
||||||
|
|
||||||
|
const queue = [];
|
||||||
|
|
||||||
|
let n = $state(1);
|
||||||
|
let fizz = $state(true);
|
||||||
|
let buzz = $state(true);
|
||||||
|
|
||||||
|
function increment() {
|
||||||
|
n++;
|
||||||
|
|
||||||
|
fizz = n % 3 === 0;
|
||||||
|
buzz = n % 5 === 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function push(value) {
|
||||||
|
if (value === 1) return 1;
|
||||||
|
const d = Promise.withResolvers();
|
||||||
|
|
||||||
|
queue.push(() => d.resolve(value));
|
||||||
|
|
||||||
|
const signal = getAbortSignal();
|
||||||
|
signal.onabort = () => d.reject(signal.reason);
|
||||||
|
|
||||||
|
return d.promise;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button onclick={increment}>
|
||||||
|
{$state.eager(n)}
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<button onclick={() => queue.shift()?.()}>shift</button>
|
||||||
|
|
||||||
|
<p>{n} = {await push(n)}</p>
|
||||||
|
|
||||||
|
{#if true}
|
||||||
|
<p>fizz: {fizz}</p>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if true}
|
||||||
|
<p>buzz: {buzz}</p>
|
||||||
|
{/if}
|
||||||
@ -0,0 +1,34 @@
|
|||||||
|
import { tick } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
async test({ assert, target }) {
|
||||||
|
await tick();
|
||||||
|
const [button1, button2, pop, shift] = target.querySelectorAll('button');
|
||||||
|
const [p] = target.querySelectorAll('p');
|
||||||
|
|
||||||
|
button1.click();
|
||||||
|
await tick();
|
||||||
|
button2.click();
|
||||||
|
await tick();
|
||||||
|
assert.htmlEqual(p.innerHTML, `0 + 0 = 0 | 0 0`);
|
||||||
|
|
||||||
|
shift.click();
|
||||||
|
await tick();
|
||||||
|
assert.htmlEqual(p.innerHTML, `0 + 0 = 0 | 0 0`);
|
||||||
|
|
||||||
|
pop.click();
|
||||||
|
await tick();
|
||||||
|
assert.htmlEqual(p.innerHTML, `0 + 0 = 0 | 0 0`);
|
||||||
|
|
||||||
|
pop.click();
|
||||||
|
await tick();
|
||||||
|
assert.htmlEqual(p.innerHTML, `1 + 0 = 1 | 1 0`);
|
||||||
|
|
||||||
|
shift.click();
|
||||||
|
await tick();
|
||||||
|
pop.click();
|
||||||
|
await tick();
|
||||||
|
assert.htmlEqual(p.innerHTML, `1 + 2 = 3 | 1 1`);
|
||||||
|
}
|
||||||
|
});
|
||||||
@ -0,0 +1,21 @@
|
|||||||
|
<script>
|
||||||
|
const queue1 = [];
|
||||||
|
const queue2 = [];
|
||||||
|
|
||||||
|
let a = $state(0);
|
||||||
|
let b = $state(0);
|
||||||
|
let c = $state(0);
|
||||||
|
let d = $state(0)
|
||||||
|
|
||||||
|
function push(value, where = 1) {
|
||||||
|
if (!value) return value;
|
||||||
|
return new Promise(r => (where === 1 ? queue1 : queue2).push(() => r(value)));
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button onclick={() => {a++;c++}}>a / c</button>
|
||||||
|
<button onclick={() => {b+=2;d++}}>b / d</button>
|
||||||
|
<button onclick={() => queue1.pop()?.()}>pop 1</button>
|
||||||
|
<button onclick={() => queue2.shift()?.()}>shift 2</button>
|
||||||
|
|
||||||
|
<p>{a} + {b} = {await push(a + b)} | {await push(c, 2)} {await push(d, 2)}</p>
|
||||||
@ -0,0 +1,34 @@
|
|||||||
|
import { tick } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
async test({ assert, target }) {
|
||||||
|
await tick();
|
||||||
|
const [button1, button2, shift_1, pop_1, shift_2] = target.querySelectorAll('button');
|
||||||
|
const [p] = target.querySelectorAll('p');
|
||||||
|
|
||||||
|
button1.click();
|
||||||
|
await tick();
|
||||||
|
button2.click();
|
||||||
|
await tick();
|
||||||
|
assert.htmlEqual(p.innerHTML, `0 + 0 = 0 | 0 0`);
|
||||||
|
|
||||||
|
pop_1.click();
|
||||||
|
await tick();
|
||||||
|
shift_2.click();
|
||||||
|
await tick();
|
||||||
|
assert.htmlEqual(p.innerHTML, `0 + 0 = 0 | 0 0`);
|
||||||
|
|
||||||
|
// Check that the first batch can still resolve before the second even if one of its async values
|
||||||
|
// is already superseeded (but the subsequent batch as a whole is still pending).
|
||||||
|
shift_1.click();
|
||||||
|
await tick();
|
||||||
|
assert.htmlEqual(p.innerHTML, `1 + 0 = 1 | 1 0`);
|
||||||
|
|
||||||
|
shift_1.click();
|
||||||
|
await tick();
|
||||||
|
shift_2.click();
|
||||||
|
await tick();
|
||||||
|
assert.htmlEqual(p.innerHTML, `1 + 2 = 3 | 1 1`);
|
||||||
|
}
|
||||||
|
});
|
||||||
@ -0,0 +1,22 @@
|
|||||||
|
<script>
|
||||||
|
const queue1 = [];
|
||||||
|
const queue2 = [];
|
||||||
|
|
||||||
|
let a = $state(0);
|
||||||
|
let b = $state(0);
|
||||||
|
let c = $state(0);
|
||||||
|
let d = $state(0)
|
||||||
|
|
||||||
|
function push(value, where = 1) {
|
||||||
|
if (!value) return value;
|
||||||
|
return new Promise(r => (where === 1 ? queue1 : queue2).push(() => r(value)));
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button onclick={() => {a++;c++}}>a / c</button>
|
||||||
|
<button onclick={() => {b+=2;d++}}>b / d</button>
|
||||||
|
<button onclick={() => queue1.shift()?.()}>shift 1</button>
|
||||||
|
<button onclick={() => queue1.pop()?.()}>pop 1</button>
|
||||||
|
<button onclick={() => queue2.shift()?.()}>shift 2</button>
|
||||||
|
|
||||||
|
<p>{a} + {b} = {await push(a + b)} | {await push(c, 2)} {await push(d, 2)}</p>
|
||||||
@ -0,0 +1,20 @@
|
|||||||
|
import { tick } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
async test({ assert, target }) {
|
||||||
|
const [increment, pop] = target.querySelectorAll('button');
|
||||||
|
|
||||||
|
increment.click();
|
||||||
|
await tick();
|
||||||
|
increment.click();
|
||||||
|
await tick();
|
||||||
|
pop.click();
|
||||||
|
await tick();
|
||||||
|
assert.htmlEqual(target.innerHTML, '<button>increment</button><button>pop</button> 2 2 1'); // showing nothing here yet would also be ok
|
||||||
|
|
||||||
|
pop.click();
|
||||||
|
await tick();
|
||||||
|
assert.htmlEqual(target.innerHTML, '<button>increment</button><button>pop</button> 2 2 1');
|
||||||
|
}
|
||||||
|
});
|
||||||
@ -0,0 +1,23 @@
|
|||||||
|
|
||||||
|
<script>
|
||||||
|
let count = $state(0);
|
||||||
|
let other = $state(0);
|
||||||
|
|
||||||
|
const queue = [];
|
||||||
|
|
||||||
|
function push(v) {
|
||||||
|
if (v === 0) return v;
|
||||||
|
|
||||||
|
return new Promise((resolve) => queue.push(() => resolve(v)));
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button onclick={() => {
|
||||||
|
if (count === 0) other++;
|
||||||
|
count++;
|
||||||
|
}}>increment</button>
|
||||||
|
<button onclick={() => queue.pop()?.()}>pop</button>
|
||||||
|
|
||||||
|
{#if count > 0}
|
||||||
|
{await push(count)} {count} {other}
|
||||||
|
{/if}
|
||||||
@ -0,0 +1 @@
|
|||||||
|
<span>x</span>
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
mode: ['client', 'server'],
|
||||||
|
|
||||||
|
html: `<span>x</span>`,
|
||||||
|
ssrHtml: `<span>x</span>`
|
||||||
|
});
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
<script>
|
||||||
|
import Icon from './Icon.svelte';
|
||||||
|
|
||||||
|
let icons = $state({ currency: { Icon } });
|
||||||
|
const platformIcons = $derived(icons);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<platformIcons.currency.Icon />
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
<script>
|
||||||
|
let {things} = $props();
|
||||||
|
|
||||||
|
$inspect(things);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
{#each things as thing}
|
||||||
|
<li>thing {thing.id}</li>
|
||||||
|
{/each}
|
||||||
|
</ul>
|
||||||
@ -0,0 +1,21 @@
|
|||||||
|
import { normalise_inspect_logs } from '../../../helpers';
|
||||||
|
import { test } from '../../test';
|
||||||
|
import { flushSync } from 'svelte';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
compileOptions: {
|
||||||
|
dev: true
|
||||||
|
},
|
||||||
|
|
||||||
|
async test({ assert, target, errors, logs }) {
|
||||||
|
const button = target.querySelector('button');
|
||||||
|
|
||||||
|
flushSync(() => {
|
||||||
|
button?.click();
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.htmlEqual(target.innerHTML, '<button>clear</button>');
|
||||||
|
assert.equal(errors.length, 0);
|
||||||
|
assert.deepEqual(normalise_inspect_logs(logs), [[{ id: 1 }, { id: 2 }]]);
|
||||||
|
}
|
||||||
|
});
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
<script>
|
||||||
|
import List from "./List.svelte"
|
||||||
|
|
||||||
|
let data = $state({things: [{id:1}, {id:2}]})
|
||||||
|
|
||||||
|
function reloadData() {
|
||||||
|
data = null
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if data}
|
||||||
|
<List things={data.things.map((t) => t)} />
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<button onclick={() => reloadData()}>clear</button>
|
||||||
@ -0,0 +1,54 @@
|
|||||||
|
import { tick } from 'svelte';
|
||||||
|
import { ok, test } from '../../test';
|
||||||
|
|
||||||
|
// Test that the store is unsubscribed from, even if it's not referenced once the store itself is set to null
|
||||||
|
export default test({
|
||||||
|
skip_no_async: true,
|
||||||
|
|
||||||
|
async test({ target, assert }) {
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`<input type="number"> <p>0</p> <button>add watcher</button>`
|
||||||
|
);
|
||||||
|
|
||||||
|
target.querySelector('button')?.click();
|
||||||
|
await tick();
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`<input type="number"> <p>1</p> hello 1 <button>remove watcher</button>`
|
||||||
|
);
|
||||||
|
|
||||||
|
const input = target.querySelector('input');
|
||||||
|
ok(input);
|
||||||
|
|
||||||
|
input.stepUp();
|
||||||
|
input.dispatchEvent(new Event('input', { bubbles: true }));
|
||||||
|
await tick();
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`<input type="number"> <p>2</p> hello 2 <button>remove watcher</button>`
|
||||||
|
);
|
||||||
|
|
||||||
|
target.querySelector('button')?.click();
|
||||||
|
await tick();
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`<input type="number"> <p>2</p> <button>add watcher</button>`
|
||||||
|
);
|
||||||
|
|
||||||
|
input.stepUp();
|
||||||
|
input.dispatchEvent(new Event('input', { bubbles: true }));
|
||||||
|
await tick();
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`<input type="number"> <p>2</p> <button>add watcher</button>`
|
||||||
|
);
|
||||||
|
|
||||||
|
target.querySelector('button')?.click();
|
||||||
|
await tick();
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`<input type="number"> <p>3</p> hello 3 <button>remove watcher</button>`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
@ -0,0 +1,29 @@
|
|||||||
|
<script>
|
||||||
|
import { writable, derived } from "svelte/store";
|
||||||
|
|
||||||
|
const obj = writable({ a: 1 });
|
||||||
|
let count = $state(0);
|
||||||
|
let watcherA = $state();
|
||||||
|
|
||||||
|
function watch (prop) {
|
||||||
|
return derived(obj, (o) => {
|
||||||
|
count++;
|
||||||
|
return o[prop];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<input type="number" bind:value={$obj.a}>
|
||||||
|
<p>{count}</p>
|
||||||
|
|
||||||
|
{#if watcherA}
|
||||||
|
<!-- make sure the presence of async work doesn't break the `legacy_updates` mechanism -->
|
||||||
|
{#if true}
|
||||||
|
{await 'hello'}
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{$watcherA}
|
||||||
|
<button on:click={() => watcherA = null}>remove watcher</button>
|
||||||
|
{:else}
|
||||||
|
<button on:click={() => watcherA = watch("a")}>add watcher</button>
|
||||||
|
{/if}
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
mode: ['async'],
|
||||||
|
compileOptions: {
|
||||||
|
dev: true
|
||||||
|
}
|
||||||
|
});
|
||||||
@ -0,0 +1 @@
|
|||||||
|
<!--[--><img alt="test" src=""/><!--]-->
|
||||||
@ -0,0 +1 @@
|
|||||||
|
<!--1410iyz--><!----><title>Async multiple attributes</title>
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
<script>
|
||||||
|
const user = $derived(Promise.resolve({
|
||||||
|
name: 'test',
|
||||||
|
image: '',
|
||||||
|
}))
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<svelte:head>
|
||||||
|
<title>Async multiple attributes</title>
|
||||||
|
</svelte:head>
|
||||||
|
|
||||||
|
<img
|
||||||
|
alt={(await user).name}
|
||||||
|
src={(await user).image}
|
||||||
|
/>
|
||||||
Loading…
Reference in new issue