Skip to content

Commit bfa9f04

Browse files
committed
tag async deriveds
1 parent 3566d21 commit bfa9f04

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

packages/svelte/src/compiler/phases/3-transform/client/visitors/VariableDeclaration.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,13 +208,16 @@ export function VariableDeclaration(node, context) {
208208

209209
if (is_async) {
210210
const location = dev && is_ignored(init, 'await_waterfall') && locate_node(init);
211-
const call = b.call(
211+
let call = b.call(
212212
'$.async_derived',
213213
b.thunk(expression, true),
214214
location ? b.literal(location) : undefined
215215
);
216216

217-
declarations.push(b.declarator(declarator.id, b.call(b.await(b.call('$.save', call)))));
217+
call = b.call(b.await(b.call('$.save', call)));
218+
if (dev) call = b.call('$.tag', call, b.literal(declarator.id.name));
219+
220+
declarations.push(b.declarator(declarator.id, call));
218221
} else {
219222
if (rune === '$derived') expression = b.thunk(expression);
220223

packages/svelte/src/internal/client/dev/tracing.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { UNINITIALIZED } from '../../../constants.js';
33
import { snapshot } from '../../shared/clone.js';
44
import { define_property } from '../../shared/utils.js';
5-
import { DERIVED, PROXY_PATH_SYMBOL, STATE_SYMBOL } from '#client/constants';
5+
import { DERIVED, EFFECT_ASYNC, PROXY_PATH_SYMBOL, STATE_SYMBOL } from '#client/constants';
66
import { effect_tracking } from '../reactivity/effects.js';
77
import { active_reaction, captured_signals, set_captured_signals, untrack } from '../runtime.js';
88

@@ -26,7 +26,7 @@ function log_entry(signal, entry) {
2626
return;
2727
}
2828

29-
const type = (signal.f & DERIVED) !== 0 ? '$derived' : '$state';
29+
const type = (signal.f & (DERIVED | EFFECT_ASYNC)) !== 0 ? '$derived' : '$state';
3030
const current_reaction = /** @type {Reaction} */ (active_reaction);
3131
const dirty = signal.wv > current_reaction.wv || current_reaction.wv === 0;
3232
const style = dirty

packages/svelte/src/internal/client/reactivity/deriveds.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import {
1010
MAYBE_DIRTY,
1111
STALE_REACTION,
1212
UNOWNED,
13-
DESTROYED
13+
DESTROYED,
14+
EFFECT_ASYNC
1415
} from '#client/constants';
1516
import {
1617
active_reaction,
@@ -188,6 +189,12 @@ export function async_derived(fn, location) {
188189
promise.then(handler, (e) => handler(null, e || 'unknown'));
189190
});
190191

192+
if (DEV) {
193+
// add a flag that lets this be printed as a derived
194+
// when using `$inspect.trace()`
195+
signal.f |= EFFECT_ASYNC;
196+
}
197+
191198
return new Promise((fulfil) => {
192199
/** @param {Promise<V>} p */
193200
function next(p) {

0 commit comments

Comments
 (0)