File tree Expand file tree Collapse file tree 3 files changed +19
-17
lines changed
packages/svelte/src/internal/client Expand file tree Collapse file tree 3 files changed +19
-17
lines changed Original file line number Diff line number Diff line change @@ -66,6 +66,8 @@ export function source(v, stack) {
6666
6767 if ( DEV && tracing_mode_flag ) {
6868 signal . created = stack ?? get_stack ( 'CreatedAt' ) ;
69+ signal . updated = null ;
70+ signal . set_during_effect = false ;
6971 }
7072
7173 return signal ;
@@ -169,10 +171,7 @@ export function internal_set(source, value) {
169171 source . updated = get_stack ( 'UpdatedAt' ) ;
170172
171173 if ( active_effect !== null ) {
172- // Signal that we should increment the write version
173- // after the current effect has run, so that it is
174- // marked dirty if the effect uses `$inspect.trace()`
175- source . trace_need_increase = true ;
174+ source . set_during_effect = true ;
176175 }
177176 }
178177
Original file line number Diff line number Diff line change @@ -16,11 +16,19 @@ export interface Value<V = unknown> extends Signal {
1616 rv : number ;
1717 /** The latest value for this signal */
1818 v : V ;
19- /** Dev only */
19+
20+ // dev-only
21+ /** A label (e.g. the `foo` in `let foo = $state(...)`) used for `$inspect.trace()` */
2022 label ?: string ;
23+ /** An error with a stack trace showing when the source was created */
2124 created ?: Error | null ;
25+ /** An error with a stack trace showing when the source was last updated */
2226 updated ?: Error | null ;
23- trace_need_increase ?: boolean ;
27+ /**
28+ * Whether or not the source was set while running an effect — if so, we need to
29+ * increment the write version so that it shows up as dirty when the effect re-runs
30+ */
31+ set_during_effect ?: boolean ;
2432}
2533
2634export interface Reaction extends Signal {
Original file line number Diff line number Diff line change @@ -442,18 +442,13 @@ export function update_effect(effect) {
442442 effect . teardown = typeof teardown === 'function' ? teardown : null ;
443443 effect . wv = write_version ;
444444
445- var deps = effect . deps ;
446-
447- // In DEV, we need to handle a case where $inspect.trace() might
448- // incorrectly state a source dependency has not changed when it has.
449- // That's beacuse that source was changed by the same effect, causing
450- // the versions to match. We can avoid this by incrementing the version
451- if ( DEV && tracing_mode_flag && ( effect . f & DIRTY ) !== 0 && deps !== null ) {
452- for ( let i = 0 ; i < deps . length ; i ++ ) {
453- var dep = deps [ i ] ;
454- if ( dep . trace_need_increase ) {
445+ // In DEV, increment versions of any sources that were written to during the effect,
446+ // so that they are correctly marked as dirty when the effect re-runs
447+ if ( DEV && tracing_mode_flag && ( effect . f & DIRTY ) !== 0 && effect . deps !== null ) {
448+ for ( var dep of effect . deps ) {
449+ if ( dep . set_during_effect ) {
455450 dep . wv = increment_write_version ( ) ;
456- dep . trace_need_increase = undefined ;
451+ dep . set_during_effect = false ;
457452 }
458453 }
459454 }
You can’t perform that action at this time.
0 commit comments