Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/svelte/src/internal/client/dev/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -514,3 +514,16 @@

return true;
}

/**
* Stringify a derived function, removing `$.track_reactivity_loss` and `$.get` etc
* @param {Function} fn
*/
export function stringify_derived(fn) {
return `{${fn.toString()
.replace(/^async \(\) => /, '')
.replace(/^\(/, '')
.replace(/\$\.get\((.+?)\)/, (_, name) => name)
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this only replaces the first occurence, not every, so either /g or replaceAll is needed. Same for track_reactivity_loss

.replace(/\$\.track_reactivity_loss\((.+?)\)\(\)/, (_, name) => name)
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
.replace(/\)$/, '')}}`;
}
3 changes: 2 additions & 1 deletion packages/svelte/src/internal/client/reactivity/deriveds.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import { batch_values, current_batch, previous_batch } from './batch.js';
import { increment_pending, unset_context } from './async.js';
import { deferred, includes, noop } from '../../shared/utils.js';
import { set_signal_status, update_derived_status } from './status.js';
import { stringify_derived } from '../dev/debug.js';

/**
* This allows us to track 'reactivity loss' that occurs when signals
Expand Down Expand Up @@ -120,7 +121,7 @@ export function async_derived(fn, label, location) {
var promise = /** @type {Promise<V>} */ (/** @type {unknown} */ (undefined));
var signal = source(/** @type {V} */ (UNINITIALIZED));

if (DEV) signal.label = label ?? fn.toString();
if (DEV) signal.label = label ?? stringify_derived(fn);

// only suspend in async deriveds created on initialisation
var should_suspend = !active_reaction;
Expand Down
Loading