@ -9,10 +9,9 @@ import {
} from '../../../../constants.js' ;
} from '../../../../constants.js' ;
import { create _event , delegate } from './events.js' ;
import { create _event , delegate } from './events.js' ;
import { add _form _reset _listener , autofocus } from './misc.js' ;
import { add _form _reset _listener , autofocus } from './misc.js' ;
import { effect , effect _root } from '../../reactivity/effects.js' ;
import * as w from '../../warnings.js' ;
import * as w from '../../warnings.js' ;
import { LOADING _ATTR _SYMBOL } from '../../constants.js' ;
import { LOADING _ATTR _SYMBOL } from '../../constants.js' ;
import { queue _idle _task } from '../task.js' ;
import { queue _idle _task , queue _micro _task } from '../task.js' ;
/ * *
/ * *
* The value / checked attribute in the template actually corresponds to the defaultValue property , so we need
* The value / checked attribute in the template actually corresponds to the defaultValue property , so we need
@ -262,21 +261,13 @@ export function set_attributes(element, prev, next, lowercase_attributes, css_ha
// On the first run, ensure that events are added after bindings so
// On the first run, ensure that events are added after bindings so
// that their listeners fire after the binding listeners
// that their listeners fire after the binding listeners
if ( ! prev ) {
if ( ! prev ) {
// In edge cases it may happen that set_attributes is re-run before the
queue _micro _task ( ( ) => {
// effect is executed. In that case the render effect which initiates this
if ( ! element . isConnected ) return ;
// re-run will destroy the inner effect and it will never run. But because
for ( const [ key , value , evt ] of events ) {
// next and prev may have the same keys, the event would not get added again
if ( current [ key ] === value ) {
// and it would get lost. We prevent this by using a root effect.
evt ( ) ;
const destroy _root = effect _root ( ( ) => {
effect ( ( ) => {
if ( ! element . isConnected ) return ;
for ( const [ key , value , evt ] of events ) {
if ( current [ key ] === value ) {
evt ( ) ;
}
}
}
destroy _root ( ) ;
}
} ) ;
} ) ;
} ) ;
}
}