@@ -78,6 +78,8 @@ let dev_effect_stack = [];
78
78
/** @type {null | Reaction } */
79
79
export let active_reaction = null ;
80
80
81
+ export let untracking = false ;
82
+
81
83
/** @param {null | Reaction } reaction */
82
84
export function set_active_reaction ( reaction ) {
83
85
active_reaction = reaction ;
@@ -423,6 +425,7 @@ export function update_reaction(reaction) {
423
425
var previous_skip_reaction = skip_reaction ;
424
426
var prev_derived_sources = derived_sources ;
425
427
var previous_component_context = component_context ;
428
+ var previous_untracking = untracking ;
426
429
var flags = reaction . f ;
427
430
428
431
new_deps = /** @type {null | Value[] } */ ( null ) ;
@@ -432,6 +435,7 @@ export function update_reaction(reaction) {
432
435
skip_reaction = ! is_flushing_effect && ( flags & UNOWNED ) !== 0 ;
433
436
derived_sources = null ;
434
437
component_context = reaction . ctx ;
438
+ untracking = false ;
435
439
read_version ++ ;
436
440
437
441
try {
@@ -495,6 +499,7 @@ export function update_reaction(reaction) {
495
499
skip_reaction = previous_skip_reaction ;
496
500
derived_sources = prev_derived_sources ;
497
501
component_context = previous_component_context ;
502
+ untracking = previous_untracking ;
498
503
}
499
504
}
500
505
@@ -934,7 +939,7 @@ export function get(signal) {
934
939
}
935
940
936
941
// Register the dependency on the current reaction signal.
937
- if ( active_reaction !== null ) {
942
+ if ( active_reaction !== null && ! untracking ) {
938
943
if ( derived_sources !== null && derived_sources . includes ( signal ) ) {
939
944
e . state_unsafe_local_read ( ) ;
940
945
}
@@ -1085,12 +1090,12 @@ export function invalidate_inner_signals(fn) {
1085
1090
* @returns {T }
1086
1091
*/
1087
1092
export function untrack ( fn ) {
1088
- const previous_reaction = active_reaction ;
1093
+ var previous_untracking = untracking ;
1089
1094
try {
1090
- active_reaction = null ;
1095
+ untracking = true ;
1091
1096
return fn ( ) ;
1092
1097
} finally {
1093
- active_reaction = previous_reaction ;
1098
+ untracking = previous_untracking ;
1094
1099
}
1095
1100
}
1096
1101
0 commit comments