@ -258,37 +258,7 @@ export function update_reaction(reaction) {
var fn = /** @type {Function} */ ( reaction . fn ) ;
var result = fn ( ) ;
reaction . f |= REACTION _RAN ;
var deps = reaction . deps ;
// Don't remove reactions during fork;
// they must remain for when fork is discarded
var is _fork = current _batch ? . is _fork ;
if ( new _deps !== null ) {
var i ;
if ( ! is _fork ) {
remove _reactions ( reaction , skipped _deps ) ;
}
if ( deps !== null && skipped _deps > 0 ) {
deps . length = skipped _deps + new _deps . length ;
for ( i = 0 ; i < new _deps . length ; i ++ ) {
deps [ skipped _deps + i ] = new _deps [ i ] ;
}
} else {
reaction . deps = deps = new _deps ;
}
if ( effect _tracking ( ) && ( reaction . f & CONNECTED ) !== 0 ) {
for ( i = skipped _deps ; i < deps . length ; i ++ ) {
( deps [ i ] . reactions ? ? = [ ] ) . push ( reaction ) ;
}
}
} else if ( ! is _fork && deps !== null && skipped _deps < deps . length ) {
remove _reactions ( reaction , skipped _deps ) ;
deps . length = skipped _deps ;
}
var deps = update _dependencies ( reaction ) ;
// 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
@ -300,7 +270,7 @@ export function update_reaction(reaction) {
deps !== null &&
( reaction . f & ( DERIVED | MAYBE _DIRTY | DIRTY ) ) === 0
) {
for ( i = 0 ; i < /** @type {Source[]} */ ( untracked _writes ) . length ; i ++ ) {
for ( var i = 0 ; i < /** @type {Source[]} */ ( untracked _writes ) . length ; i ++ ) {
schedule _possible _effect _self _invalidation (
untracked _writes [ i ] ,
/** @type {Effect} */ ( reaction )
@ -344,6 +314,9 @@ export function update_reaction(reaction) {
return result ;
} catch ( error ) {
// still commit the deps read before the throw, otherwise deriveds connected by this run keep no reader and the reaction never re-runs when they change
update _dependencies ( reaction ) ;
return handle _error ( error ) ;
} finally {
reaction . f ^= REACTION _IS _UPDATING ;
@ -358,6 +331,45 @@ export function update_reaction(reaction) {
}
}
/ * *
* @ param { Reaction } reaction
* /
function update _dependencies ( reaction ) {
var deps = reaction . deps ;
// Don't remove reactions during fork;
// they must remain for when fork is discarded
var is _fork = current _batch ? . is _fork ;
if ( new _deps !== null ) {
var i ;
if ( ! is _fork ) {
remove _reactions ( reaction , skipped _deps ) ;
}
if ( deps !== null && skipped _deps > 0 ) {
deps . length = skipped _deps + new _deps . length ;
for ( i = 0 ; i < new _deps . length ; i ++ ) {
deps [ skipped _deps + i ] = new _deps [ i ] ;
}
} else {
reaction . deps = deps = new _deps ;
}
if ( effect _tracking ( ) && ( reaction . f & CONNECTED ) !== 0 ) {
for ( i = skipped _deps ; i < deps . length ; i ++ ) {
( deps [ i ] . reactions ? ? = [ ] ) . push ( reaction ) ;
}
}
} else if ( ! is _fork && deps !== null && skipped _deps < deps . length ) {
remove _reactions ( reaction , skipped _deps ) ;
deps . length = skipped _deps ;
}
return deps ;
}
/ * *
* @ template V
* @ param { Reaction } signal