diff --git a/.changeset/forty-chicken-heal.md b/.changeset/forty-chicken-heal.md new file mode 100644 index 0000000000..6370c007b9 --- /dev/null +++ b/.changeset/forty-chicken-heal.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: use `internal_set` in `await` block diff --git a/packages/svelte/src/internal/client/dom/blocks/await.js b/packages/svelte/src/internal/client/dom/blocks/await.js index 3a282345a7..75bbb23cdd 100644 --- a/packages/svelte/src/internal/client/dom/blocks/await.js +++ b/packages/svelte/src/internal/client/dom/blocks/await.js @@ -1,19 +1,19 @@ /** @import { Effect, Source, TemplateNode } from '#client' */ -import { is_promise, noop } from '../../../shared/utils.js'; +import { DEV } from 'esm-env'; +import { is_promise } from '../../../shared/utils.js'; +import { block, branch, pause_effect, resume_effect } from '../../reactivity/effects.js'; +import { internal_set, mutable_source, source } from '../../reactivity/sources.js'; import { component_context, flush_sync, is_runes, - set_component_context, set_active_effect, set_active_reaction, + set_component_context, set_dev_current_component_function } from '../../runtime.js'; -import { block, branch, pause_effect, resume_effect } from '../../reactivity/effects.js'; -import { DEV } from 'esm-env'; -import { queue_micro_task } from '../task.js'; import { hydrate_next, hydrate_node, hydrating } from '../hydration.js'; -import { mutable_source, set, source } from '../../reactivity/sources.js'; +import { queue_micro_task } from '../task.js'; const PENDING = 0; const THEN = 1; @@ -120,12 +120,16 @@ export function await_block(node, get_input, pending_fn, then_fn, catch_fn) { promise.then( (value) => { if (promise !== input) return; - set(input_source, value); + // we technically could use `set` here since it's on the next microtick + // but let's use internal_set for consistency and just to be safe + internal_set(input_source, value); update(THEN, true); }, (error) => { if (promise !== input) return; - set(error_source, error); + // we technically could use `set` here since it's on the next microtick + // but let's use internal_set for consistency and just to be safe + internal_set(error_source, error); update(CATCH, true); } ); @@ -142,7 +146,7 @@ export function await_block(node, get_input, pending_fn, then_fn, catch_fn) { }); } } else { - set(input_source, input); + internal_set(input_source, input); update(THEN, false); } diff --git a/packages/svelte/tests/runtime-runes/samples/await-non-promise/_config.js b/packages/svelte/tests/runtime-runes/samples/await-non-promise/_config.js new file mode 100644 index 0000000000..14dac30350 --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/await-non-promise/_config.js @@ -0,0 +1,9 @@ +import { flushSync } from 'svelte'; +import { test } from '../../test'; + +export default test({ + compileOptions: { + dev: true + }, + test() {} +}); diff --git a/packages/svelte/tests/runtime-runes/samples/await-non-promise/main.svelte b/packages/svelte/tests/runtime-runes/samples/await-non-promise/main.svelte new file mode 100644 index 0000000000..62881ba666 --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/await-non-promise/main.svelte @@ -0,0 +1,9 @@ + + +{#await count} + loading +{:then count} + {count} +{/await} \ No newline at end of file