diff --git a/packages/svelte/src/internal/client/runtime.js b/packages/svelte/src/internal/client/runtime.js index ddcdb7a163..1ba46af4a1 100644 --- a/packages/svelte/src/internal/client/runtime.js +++ b/packages/svelte/src/internal/client/runtime.js @@ -734,7 +734,7 @@ export function get(signal) { // Keep batch-local reads and stale-reader tracking out of the common read path. // Function extraction makes it a bit easier for engines to optimize the get function. - if (held_sources !== null || stale_sources !== null || batch_values !== null) { + if (batch_values !== null) { return get_batch_value(signal, first_time); } 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..75f5d51983 --- /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 and does not connect the batch +// to the (pending) batch that wrote it, unlike a regular read, which has to wait for it +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

1`); + + 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}