fix: use `internal_set` in `await` block (#13642)

pull/13648/head
Paolo Ricciuti 2 months ago committed by GitHub
parent 440017d442
commit 372884cf99
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: use `internal_set` in `await` block

@ -1,19 +1,19 @@
/** @import { Effect, Source, TemplateNode } from '#client' */ /** @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 { import {
component_context, component_context,
flush_sync, flush_sync,
is_runes, is_runes,
set_component_context,
set_active_effect, set_active_effect,
set_active_reaction, set_active_reaction,
set_component_context,
set_dev_current_component_function set_dev_current_component_function
} from '../../runtime.js'; } 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 { 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 PENDING = 0;
const THEN = 1; const THEN = 1;
@ -120,12 +120,16 @@ export function await_block(node, get_input, pending_fn, then_fn, catch_fn) {
promise.then( promise.then(
(value) => { (value) => {
if (promise !== input) return; 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); update(THEN, true);
}, },
(error) => { (error) => {
if (promise !== input) return; 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); update(CATCH, true);
} }
); );
@ -142,7 +146,7 @@ export function await_block(node, get_input, pending_fn, then_fn, catch_fn) {
}); });
} }
} else { } else {
set(input_source, input); internal_set(input_source, input);
update(THEN, false); update(THEN, false);
} }

@ -0,0 +1,9 @@
import { flushSync } from 'svelte';
import { test } from '../../test';
export default test({
compileOptions: {
dev: true
},
test() {}
});

@ -0,0 +1,9 @@
<script>
let count = $state(43);
</script>
{#await count}
loading
{:then count}
{count}
{/await}
Loading…
Cancel
Save