Skip to content

Commit 372884c

Browse files
fix: use internal_set in await block (#13642)
1 parent 440017d commit 372884c

File tree

4 files changed

+36
-9
lines changed

4 files changed

+36
-9
lines changed

.changeset/forty-chicken-heal.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: use `internal_set` in `await` block

packages/svelte/src/internal/client/dom/blocks/await.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
/** @import { Effect, Source, TemplateNode } from '#client' */
2-
import { is_promise, noop } from '../../../shared/utils.js';
2+
import { DEV } from 'esm-env';
3+
import { is_promise } from '../../../shared/utils.js';
4+
import { block, branch, pause_effect, resume_effect } from '../../reactivity/effects.js';
5+
import { internal_set, mutable_source, source } from '../../reactivity/sources.js';
36
import {
47
component_context,
58
flush_sync,
69
is_runes,
7-
set_component_context,
810
set_active_effect,
911
set_active_reaction,
12+
set_component_context,
1013
set_dev_current_component_function
1114
} from '../../runtime.js';
12-
import { block, branch, pause_effect, resume_effect } from '../../reactivity/effects.js';
13-
import { DEV } from 'esm-env';
14-
import { queue_micro_task } from '../task.js';
1515
import { hydrate_next, hydrate_node, hydrating } from '../hydration.js';
16-
import { mutable_source, set, source } from '../../reactivity/sources.js';
16+
import { queue_micro_task } from '../task.js';
1717

1818
const PENDING = 0;
1919
const THEN = 1;
@@ -120,12 +120,16 @@ export function await_block(node, get_input, pending_fn, then_fn, catch_fn) {
120120
promise.then(
121121
(value) => {
122122
if (promise !== input) return;
123-
set(input_source, value);
123+
// we technically could use `set` here since it's on the next microtick
124+
// but let's use internal_set for consistency and just to be safe
125+
internal_set(input_source, value);
124126
update(THEN, true);
125127
},
126128
(error) => {
127129
if (promise !== input) return;
128-
set(error_source, error);
130+
// we technically could use `set` here since it's on the next microtick
131+
// but let's use internal_set for consistency and just to be safe
132+
internal_set(error_source, error);
129133
update(CATCH, true);
130134
}
131135
);
@@ -142,7 +146,7 @@ export function await_block(node, get_input, pending_fn, then_fn, catch_fn) {
142146
});
143147
}
144148
} else {
145-
set(input_source, input);
149+
internal_set(input_source, input);
146150
update(THEN, false);
147151
}
148152

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { flushSync } from 'svelte';
2+
import { test } from '../../test';
3+
4+
export default test({
5+
compileOptions: {
6+
dev: true
7+
},
8+
test() {}
9+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<script>
2+
let count = $state(43);
3+
</script>
4+
5+
{#await count}
6+
loading
7+
{:then count}
8+
{count}
9+
{/await}

0 commit comments

Comments
 (0)