From 180df1d513f3aded8559fcc7bf160e7075af1bd5 Mon Sep 17 00:00:00 2001 From: Simon Holthausen Date: Thu, 27 Aug 2026 14:46:40 +0200 Subject: [PATCH] one more (very contrived) test --- .../_config.js | 61 +++++++++++++++++++ .../main.svelte | 49 +++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 packages/svelte/tests/runtime-runes/samples/async-read-pending-value-in-committed-batch/_config.js create mode 100644 packages/svelte/tests/runtime-runes/samples/async-read-pending-value-in-committed-batch/main.svelte diff --git a/packages/svelte/tests/runtime-runes/samples/async-read-pending-value-in-committed-batch/_config.js b/packages/svelte/tests/runtime-runes/samples/async-read-pending-value-in-committed-batch/_config.js new file mode 100644 index 0000000000..6a65bb3c1a --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/async-read-pending-value-in-committed-batch/_config.js @@ -0,0 +1,61 @@ +import { tick } from 'svelte'; +import { test } from '../../test'; + +const buttons = ` + + + + + + +`; + +export default test({ + async test({ assert, target }) { + await tick(); + + const [up, down, show1, show2, shift_a, shift_t] = target.querySelectorAll('button'); + + // batch B: reveals boundary 1 -> commits with pending snippet, stays live + show1.click(); + await tick(); + assert.htmlEqual(target.innerHTML, `${buttons}

loading 1...

`); + + // batch C: reveals boundary 2 -> commits with pending snippet, stays live + show2.click(); + await tick(); + assert.htmlEqual(target.innerHTML, `${buttons}

loading 1...

loading 2...

`); + + // batch A: writes a=1; the async-a effect is owned by C, so A merges with + // C and stays pending. B remains separate + up.click(); + await tick(); + + // B's continuation first-reads `a`, which is overlaid by the pending + // merged batch. B has already committed its UI, so it cannot entangle — + // it reads the latest value (1) instead + shift_t.click(); + await tick(); + assert.htmlEqual(target.innerHTML, `${buttons}

late read: 1

loading 2...

`); + + // revert `a` to 0 inside the pending batch — its eventual commit leaves + // `a` unchanged. The write re-runs the late reader (it acquired `a` as a + // dependency), so it re-awaits a fresh deferred + down.click(); + await tick(); + + // resolve the pending batch's async-a runs -> it commits + shift_a.click(); + await tick(); + shift_a.click(); + await tick(); + shift_a.click(); + await tick(); + assert.htmlEqual(target.innerHTML, `${buttons}

late read: 1

async a: 0

`); + + // resolve the late reader's re-run -> it converges on the committed value + shift_t.click(); + await tick(); + assert.htmlEqual(target.innerHTML, `${buttons}

late read: 0

async a: 0

`); + } +}); diff --git a/packages/svelte/tests/runtime-runes/samples/async-read-pending-value-in-committed-batch/main.svelte b/packages/svelte/tests/runtime-runes/samples/async-read-pending-value-in-committed-batch/main.svelte new file mode 100644 index 0000000000..78ca377225 --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/async-read-pending-value-in-committed-batch/main.svelte @@ -0,0 +1,49 @@ + + + + + + + + + +{#if show1} + + +

late read: {(await push('t', 0)) > 0 ? a : -1}

+ + {#snippet pending()} +

loading 1...

+ {/snippet} +
+{/if} + +{#if show2} + +

async a: {await push('a', a)}

+ + {#snippet pending()} +

loading 2...

+ {/snippet} +
+{/if}