@@ -16,7 +16,8 @@ import {
1616 set_is_destroying_effect ,
1717 set_is_flushing_effect ,
1818 set_signal_status ,
19- untrack
19+ untrack ,
20+ set_active_effect
2021} from '../runtime.js' ;
2122import {
2223 DIRTY ,
@@ -376,11 +377,14 @@ export function destroy_effect(effect, remove_dom = true) {
376377 var node = effect . nodes_start ;
377378 var end = effect . nodes_end ;
378379 var previous_reaction = active_reaction ;
380+ var previous_effect = active_effect ;
379381
380382 // Really we only need to do this in Chromium because of https://chromestatus.com/feature/5128696823545856,
381383 // as removal of the DOM can cause sync `blur` events to fire, which can cause logic to run inside
382- // the current `active_reaction`, which isn't what we want at all
384+ // the current `active_reaction`, which isn't what we want at all. Additionally, the blur event handler
385+ // might create a derived or effect and they will be incorrectly attached to the wrong thing
383386 set_active_reaction ( null ) ;
387+ set_active_effect ( null ) ;
384388 while ( node !== null ) {
385389 /** @type {TemplateNode | null } */
386390 var next = node === end ? null : /** @type {TemplateNode } */ ( get_next_sibling ( node ) ) ;
@@ -389,6 +393,7 @@ export function destroy_effect(effect, remove_dom = true) {
389393 node = next ;
390394 }
391395 set_active_reaction ( previous_reaction ) ;
396+ set_active_effect ( previous_effect ) ;
392397
393398 removed = true ;
394399 }
0 commit comments