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) {
66
66
67
67
if ( DEV && tracing_mode_flag ) {
68
68
signal . created = stack ?? get_stack ( 'CreatedAt' ) ;
69
+ signal . updated = null ;
70
+ signal . set_during_effect = false ;
69
71
}
70
72
71
73
return signal ;
@@ -169,10 +171,7 @@ export function internal_set(source, value) {
169
171
source . updated = get_stack ( 'UpdatedAt' ) ;
170
172
171
173
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 ;
176
175
}
177
176
}
178
177
Original file line number Diff line number Diff line change @@ -16,11 +16,19 @@ export interface Value<V = unknown> extends Signal {
16
16
rv : number ;
17
17
/** The latest value for this signal */
18
18
v : V ;
19
- /** Dev only */
19
+
20
+ // dev-only
21
+ /** A label (e.g. the `foo` in `let foo = $state(...)`) used for `$inspect.trace()` */
20
22
label ?: string ;
23
+ /** An error with a stack trace showing when the source was created */
21
24
created ?: Error | null ;
25
+ /** An error with a stack trace showing when the source was last updated */
22
26
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 ;
24
32
}
25
33
26
34
export interface Reaction extends Signal {
Original file line number Diff line number Diff line change @@ -442,18 +442,13 @@ export function update_effect(effect) {
442
442
effect . teardown = typeof teardown === 'function' ? teardown : null ;
443
443
effect . wv = write_version ;
444
444
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 ) {
455
450
dep . wv = increment_write_version ( ) ;
456
- dep . trace_need_increase = undefined ;
451
+ dep . set_during_effect = false ;
457
452
}
458
453
}
459
454
}
You can’t perform that action at this time.
0 commit comments