@@ -196,45 +196,35 @@ export function check_dirtiness(reaction) {
196196
197197 if ( dependencies !== null ) {
198198 var i ;
199+ var dependency ;
200+ var depedency_needs_linking =
201+ ( flags & DISCONNECTED ) !== 0 || ( is_unowned && active_effect !== null && ! skip_reaction ) ;
199202
200- if ( ( flags & DISCONNECTED ) !== 0 ) {
203+ // If we are working with a disconnected or an unowned signal as part of an effect (due to !skip_reaction)
204+ // then we need to re-connect the reaction to the dependency
205+ if ( depedency_needs_linking ) {
201206 for ( i = 0 ; i < dependencies . length ; i ++ ) {
202- ( dependencies [ i ] . reactions ??= [ ] ) . push ( reaction ) ;
207+ dependency = dependencies [ i ] ;
208+
209+ if ( ! dependency ?. reactions ?. includes ( reaction ) ) {
210+ ( dependency . reactions ??= [ ] ) . push ( reaction ) ;
211+ }
203212 }
204213
205214 reaction . f ^= DISCONNECTED ;
206215 }
207216
208- var unowned_dirty = false ;
209-
210217 for ( i = 0 ; i < dependencies . length ; i ++ ) {
211- var dependency = dependencies [ i ] ;
218+ dependency = dependencies [ i ] ;
212219
213- if ( ! unowned_dirty && check_dirtiness ( /** @type {Derived } */ ( dependency ) ) ) {
220+ if ( check_dirtiness ( /** @type {Derived } */ ( dependency ) ) ) {
214221 update_derived ( /** @type {Derived } */ ( dependency ) ) ;
215222 }
216223
217- var version_mismatch = dependency . version > reaction . version ;
218-
219- // If we are working with an unowned signal as part of an effect (due to !skip_reaction)
220- // and the version hasn't changed, we still need to check that this reaction
221- // is linked to the dependency source – otherwise future updates will not be caught.
222- if ( is_unowned && active_effect !== null && ! skip_reaction ) {
223- if ( ! dependency ?. reactions ?. includes ( reaction ) ) {
224- ( dependency . reactions ??= [ ] ) . push ( reaction ) ;
225- }
226-
227- if ( version_mismatch ) {
228- unowned_dirty = true ;
229- }
230- } else if ( version_mismatch ) {
224+ if ( dependency . version > reaction . version ) {
231225 return true ;
232226 }
233227 }
234-
235- if ( unowned_dirty ) {
236- return true ;
237- }
238228 }
239229
240230 // Unowned signals should never be marked as clean unless they
0 commit comments