@@ -184,19 +184,29 @@ export function check_dirtiness(reaction) {
184184 // If we are working with a disconnected or an unowned signal that is now connected (due to an active effect)
185185 // then we need to re-connect the reaction to the dependency
186186 if ( is_disconnected || is_unowned_connected ) {
187+ var derived = /** @type {Derived } */ ( reaction ) ;
188+
187189 for ( i = 0 ; i < length ; i ++ ) {
188190 dependency = dependencies [ i ] ;
189191
190192 // We always re-add all reactions (even duplicates) if the derived was
191193 // previously disconnected, however we don't if it was unowned as we
192194 // de-duplicate dependencies in that case
193- if ( is_disconnected || ! dependency ?. reactions ?. includes ( reaction ) ) {
194- ( dependency . reactions ??= [ ] ) . push ( reaction ) ;
195+ if ( is_disconnected || ! dependency ?. reactions ?. includes ( derived ) ) {
196+ ( dependency . reactions ??= [ ] ) . push ( derived ) ;
195197 }
196198 }
197199
198200 if ( is_disconnected ) {
199- reaction . f ^= DISCONNECTED ;
201+ derived . f ^= DISCONNECTED ;
202+ }
203+ var parent = derived . parent ;
204+
205+ if ( is_unowned_connected && parent !== null && ( parent . f & UNOWNED ) === 0 ) {
206+ // If the derived is owned by another derived then mark it as owned agaub
207+ // as the derived value might have been referenced in a different context
208+ // and now has a reacive context managing it
209+ derived . f ^= UNOWNED ;
200210 }
201211 }
202212
@@ -409,6 +419,10 @@ export function update_reaction(reaction) {
409419 ( flags & UNOWNED ) !== 0 &&
410420 ( ! is_flushing_effect || previous_reaction === null || previous_untracking ) ;
411421
422+ if ( skip_reaction ) {
423+ // debugger
424+ }
425+
412426 derived_sources = null ;
413427 set_component_context ( reaction . ctx ) ;
414428 untracking = false ;
0 commit comments