@@ -78,6 +78,8 @@ let dev_effect_stack = [];
7878/** @type {null | Reaction } */
7979export let active_reaction = null ;
8080
81+ export let untracking = false ;
82+
8183/** @param {null | Reaction } reaction */
8284export function set_active_reaction ( reaction ) {
8385 active_reaction = reaction ;
@@ -423,6 +425,7 @@ export function update_reaction(reaction) {
423425 var previous_skip_reaction = skip_reaction ;
424426 var prev_derived_sources = derived_sources ;
425427 var previous_component_context = component_context ;
428+ var previous_untracking = untracking ;
426429 var flags = reaction . f ;
427430
428431 new_deps = /** @type {null | Value[] } */ ( null ) ;
@@ -432,6 +435,7 @@ export function update_reaction(reaction) {
432435 skip_reaction = ! is_flushing_effect && ( flags & UNOWNED ) !== 0 ;
433436 derived_sources = null ;
434437 component_context = reaction . ctx ;
438+ untracking = false ;
435439 read_version ++ ;
436440
437441 try {
@@ -495,6 +499,7 @@ export function update_reaction(reaction) {
495499 skip_reaction = previous_skip_reaction ;
496500 derived_sources = prev_derived_sources ;
497501 component_context = previous_component_context ;
502+ untracking = previous_untracking ;
498503 }
499504}
500505
@@ -934,7 +939,7 @@ export function get(signal) {
934939 }
935940
936941 // Register the dependency on the current reaction signal.
937- if ( active_reaction !== null ) {
942+ if ( active_reaction !== null && ! untracking ) {
938943 if ( derived_sources !== null && derived_sources . includes ( signal ) ) {
939944 e . state_unsafe_local_read ( ) ;
940945 }
@@ -1085,12 +1090,12 @@ export function invalidate_inner_signals(fn) {
10851090 * @returns {T }
10861091 */
10871092export function untrack ( fn ) {
1088- const previous_reaction = active_reaction ;
1093+ var previous_untracking = untracking ;
10891094 try {
1090- active_reaction = null ;
1095+ untracking = true ;
10911096 return fn ( ) ;
10921097 } finally {
1093- active_reaction = previous_reaction ;
1098+ untracking = previous_untracking ;
10941099 }
10951100}
10961101
0 commit comments