@ -382,6 +382,34 @@ export function handle_error(error, effect, previous_effect, component_context)
}
}
/ * *
* @ param { Value } signal
* @ param { Effect } effect
* @ param { number } [ depth ]
* /
function schedule _possible _effect _self _invalidation ( signal , effect , depth = 0 ) {
var reactions = signal . reactions ;
if ( reactions === null ) return ;
for ( var i = 0 ; i < reactions . length ; i ++ ) {
var reaction = reactions [ i ] ;
if ( ( reaction . f & DERIVED ) !== 0 ) {
schedule _possible _effect _self _invalidation (
/** @type {Derived} */ ( reaction ) ,
effect ,
depth + 1
) ;
} else if ( effect === reaction ) {
if ( depth === 0 ) {
set _signal _status ( reaction , DIRTY ) ;
} else if ( ( reaction . f & CLEAN ) !== 0 ) {
set _signal _status ( reaction , MAYBE _DIRTY ) ;
}
schedule _effect ( /** @type {Effect} */ ( reaction ) ) ;
}
}
}
/ * *
* @ template V
* @ param { Reaction } reaction
@ -434,6 +462,22 @@ export function update_reaction(reaction) {
deps . length = skipped _deps ;
}
// If we're inside an effect and we have untracked writes, then we need to
// ensure that if any of those untracked writes result in re-invalidation
// of the current effect, then that happens accordingly
if (
is _runes ( ) &&
untracked _writes !== null &&
( reaction . f & ( DERIVED | MAYBE _DIRTY | DIRTY ) ) === 0
) {
for ( i = 0 ; i < /** @type {Source[]} */ ( untracked _writes ) . length ; i ++ ) {
schedule _possible _effect _self _invalidation (
untracked _writes [ i ] ,
/** @type {Effect} */ ( reaction )
) ;
}
}
// If we are returning to an previous reaction then
// we need to increment the read version to ensure that
// any dependencies in this reaction aren't marked with
@ -907,17 +951,6 @@ export function get(signal) {
} else {
new _deps . push ( signal ) ;
}
if (
untracked _writes !== null &&
active _effect !== null &&
( active _effect . f & CLEAN ) !== 0 &&
( active _effect . f & BRANCH _EFFECT ) === 0 &&
untracked _writes . includes ( signal )
) {
set _signal _status ( active _effect , DIRTY ) ;
schedule _effect ( active _effect ) ;
}
}
} else if ( is _derived && /** @type {Derived} */ ( signal ) . deps === null ) {
var derived = /** @type {Derived} */ ( signal ) ;