From a841a29407e0892bcecb8b814d4f0e864cae635d Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 15 Oct 2026 06:37:33 -0400 Subject: [PATCH] chore: bring over passing async-eager tests (#19011) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit more tests from #18880 that already pass on `main`. On that branch, there are four new tests that use `$state.eager`: 1. async-eager-batch-no-merge 2. async-eager-new-in-earlier-batch 3. async-eager-read-new-dependency 4. async-state-eager-not-connected 1 describes undesirable behaviour (see https://github.com/sveltejs/svelte/pull/18880#discussion_r4271899616). The other three already pass on `main` — the changes to the implementation on #18880 (the `is_eager` stuff) are counteracting other things that changed on that branch. Of those, this brings over 2 and 4. 3 is unnecessary — the `$state.eager` in 3 isn't doing anything (`show` doesn't have any async dependents). --- .../_config.js | 33 ++++++++++++++++++ .../main.svelte | 26 ++++++++++++++ .../_config.js | 34 +++++++++++++++++++ .../main.svelte | 27 +++++++++++++++ 4 files changed, 120 insertions(+) create mode 100644 packages/svelte/tests/runtime-runes/samples/async-eager-new-in-earlier-batch/_config.js create mode 100644 packages/svelte/tests/runtime-runes/samples/async-eager-new-in-earlier-batch/main.svelte create mode 100644 packages/svelte/tests/runtime-runes/samples/async-state-eager-not-connected/_config.js create mode 100644 packages/svelte/tests/runtime-runes/samples/async-state-eager-not-connected/main.svelte diff --git a/packages/svelte/tests/runtime-runes/samples/async-eager-new-in-earlier-batch/_config.js b/packages/svelte/tests/runtime-runes/samples/async-eager-new-in-earlier-batch/_config.js new file mode 100644 index 0000000000..6d1421682d --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/async-eager-new-in-earlier-batch/_config.js @@ -0,0 +1,33 @@ +import { tick } from 'svelte'; +import { test } from '../../test'; + +// The eager expression is created while the earlier batch is processed, in whose view `x` is +// still 0. It reads the real (latest) value nonetheless, so it should not be re-run later on +export default test({ + async test({ assert, target, logs }) { + await tick(); + const [a, x, shift] = target.querySelectorAll('button'); + + a.click(); + await tick(); + x.click(); + await tick(); + assert.deepEqual(logs, []); + + shift.click(); + await tick(); + assert.htmlEqual( + target.innerHTML, + '

1

0' + ); + assert.deepEqual(logs, [1]); + + shift.click(); + await tick(); + assert.htmlEqual( + target.innerHTML, + '

1

1' + ); + assert.deepEqual(logs, [1]); + } +}); diff --git a/packages/svelte/tests/runtime-runes/samples/async-eager-new-in-earlier-batch/main.svelte b/packages/svelte/tests/runtime-runes/samples/async-eager-new-in-earlier-batch/main.svelte new file mode 100644 index 0000000000..de09e363f1 --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/async-eager-new-in-earlier-batch/main.svelte @@ -0,0 +1,26 @@ + + + + + + +{#if await delay(a)} +

{$state.eager(log(x))}

+{/if} + +{await delay(x)} diff --git a/packages/svelte/tests/runtime-runes/samples/async-state-eager-not-connected/_config.js b/packages/svelte/tests/runtime-runes/samples/async-state-eager-not-connected/_config.js new file mode 100644 index 0000000000..fe7cdb5929 --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/async-state-eager-not-connected/_config.js @@ -0,0 +1,34 @@ +import { tick } from 'svelte'; +import { test } from '../../test'; + +const buttons = ` + + + + +`; + +// Reading a value via `$state.eager` sees the latest value, unlike a regular read, which +// sees the value from before the (pending) batch wrote it until that batch commits +export default test({ + async test({ assert, target }) { + await tick(); + const [count, eager, plain, shift] = target.querySelectorAll('button'); + + count.click(); + await tick(); + assert.htmlEqual(target.innerHTML, `${buttons}

0

`); + + eager.click(); + await tick(); + assert.htmlEqual(target.innerHTML, `${buttons}

0

1`); + + plain.click(); + await tick(); + assert.htmlEqual(target.innerHTML, `${buttons}

0

10`); + + shift.click(); + await tick(); + assert.htmlEqual(target.innerHTML, `${buttons}

1

11`); + } +}); diff --git a/packages/svelte/tests/runtime-runes/samples/async-state-eager-not-connected/main.svelte b/packages/svelte/tests/runtime-runes/samples/async-state-eager-not-connected/main.svelte new file mode 100644 index 0000000000..c153314e03 --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/async-state-eager-not-connected/main.svelte @@ -0,0 +1,27 @@ + + + + + + + +

{await delay(count)}

+ +{#if eager} + {$state.eager(count)} +{/if} + +{#if plain} + {count} +{/if}