chore: eagerly assign labels to async deriveds (#17420)

pull/17425/head
Rich Harris 8 months ago committed by GitHub
parent b1f44c46c3
commit 37f08493c9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -209,11 +209,11 @@ export function VariableDeclaration(node, context) {
let call = b.call(
'$.async_derived',
b.thunk(expression, true),
dev && b.literal(declarator.id.name),
location ? b.literal(location) : undefined
);
call = should_save ? save(call) : b.await(call);
if (dev) call = b.call('$.tag', call, b.literal(declarator.id.name));
declarations.push(b.declarator(declarator.id, call));
} else {
@ -244,17 +244,16 @@ export function VariableDeclaration(node, context) {
call = b.call(
'$.async_derived',
b.thunk(expression, true),
dev &&
b.literal(
`[$derived ${declarator.id.type === 'ArrayPattern' ? 'iterable' : 'object'}]`
),
location ? b.literal(location) : undefined
);
call = should_save ? save(call) : b.await(call);
}
if (dev) {
const label = `[$derived ${declarator.id.type === 'ArrayPattern' ? 'iterable' : 'object'}]`;
call = b.call('$.tag', call, b.literal(label));
}
declarations.push(b.declarator(id, call));
}

@ -93,11 +93,12 @@ export function derived(fn) {
/**
* @template V
* @param {() => V | Promise<V>} fn
* @param {string} [label]
* @param {string} [location] If provided, print a warning if the value is not read immediately after update
* @returns {Promise<Source<V>>}
*/
/*#__NO_SIDE_EFFECTS__*/
export function async_derived(fn, location) {
export function async_derived(fn, label, location) {
let parent = /** @type {Effect | null} */ (active_effect);
if (parent === null) {
@ -109,6 +110,8 @@ export function async_derived(fn, location) {
var promise = /** @type {Promise<V>} */ (/** @type {unknown} */ (undefined));
var signal = source(/** @type {V} */ (UNINITIALIZED));
if (DEV) signal.label = label;
// only suspend in async deriveds created on initialisation
var should_suspend = !active_reaction;

Loading…
Cancel
Save