@@ -83,6 +83,8 @@ let dev_effect_stack = [];
83
83
/** @type {null | Reaction } */
84
84
export let active_reaction = null ;
85
85
86
+ export let untracking = false ;
87
+
86
88
/** @param {null | Reaction } reaction */
87
89
export function set_active_reaction ( reaction ) {
88
90
active_reaction = reaction ;
@@ -428,6 +430,7 @@ export function update_reaction(reaction) {
428
430
var previous_skip_reaction = skip_reaction ;
429
431
var prev_derived_sources = derived_sources ;
430
432
var previous_component_context = component_context ;
433
+ var previous_untracking = untracking ;
431
434
var flags = reaction . f ;
432
435
433
436
new_deps = /** @type {null | Value[] } */ ( null ) ;
@@ -437,6 +440,7 @@ export function update_reaction(reaction) {
437
440
skip_reaction = ! is_flushing_effect && ( flags & UNOWNED ) !== 0 ;
438
441
derived_sources = null ;
439
442
component_context = reaction . ctx ;
443
+ untracking = false ;
440
444
read_version ++ ;
441
445
442
446
try {
@@ -502,6 +506,7 @@ export function update_reaction(reaction) {
502
506
skip_reaction = previous_skip_reaction ;
503
507
derived_sources = prev_derived_sources ;
504
508
component_context = previous_component_context ;
509
+ untracking = previous_untracking ;
505
510
}
506
511
}
507
512
@@ -944,7 +949,7 @@ export function get(signal) {
944
949
}
945
950
946
951
// Register the dependency on the current reaction signal.
947
- if ( active_reaction !== null ) {
952
+ if ( active_reaction !== null && ! untracking ) {
948
953
if ( derived_sources !== null && derived_sources . includes ( signal ) ) {
949
954
e . state_unsafe_local_read ( ) ;
950
955
}
@@ -1117,12 +1122,12 @@ export function invalidate_inner_signals(fn) {
1117
1122
* @returns {T }
1118
1123
*/
1119
1124
export function untrack ( fn ) {
1120
- const previous_reaction = active_reaction ;
1125
+ var previous_untracking = untracking ;
1121
1126
try {
1122
- active_reaction = null ;
1127
+ untracking = true ;
1123
1128
return fn ( ) ;
1124
1129
} finally {
1125
- active_reaction = previous_reaction ;
1130
+ untracking = previous_untracking ;
1126
1131
}
1127
1132
}
1128
1133
0 commit comments