@ -144,6 +144,7 @@ export function set_custom_element_data(node, prop, value) {
* /
export function set _attributes ( element , prev , next , lowercase _attributes , css _hash ) {
var has _hash = css _hash . length !== 0 ;
var current = prev || { } ;
for ( var key in prev ) {
if ( ! ( key in next ) ) {
@ -167,7 +168,10 @@ export function set_attributes(element, prev, next, lowercase_attributes, css_ha
for ( const key in next ) {
// let instead of var because referenced in a closure
let value = next [ key ] ;
if ( value === prev ? . [ key ] ) continue ;
var prev _value = current [ key ] ;
if ( value === prev _value ) continue ;
current [ key ] = value ;
var prefix = key [ 0 ] + key [ 1 ] ; // this is faster than key.slice(0, 2)
if ( prefix === '$$' ) continue ;
@ -175,6 +179,7 @@ export function set_attributes(element, prev, next, lowercase_attributes, css_ha
if ( prefix === 'on' ) {
/** @type {{ capture?: true }} */
const opts = { } ;
const event _handle _key = '$$' + key ;
let event _name = key . slice ( 2 ) ;
var delegated = DelegatedEvents . includes ( event _name ) ;
@ -183,21 +188,35 @@ export function set_attributes(element, prev, next, lowercase_attributes, css_ha
opts . capture = true ;
}
if ( ! delegated && prev ? . [ key ] ) {
element . removeEventListener ( event _name , /** @type {any} */ ( prev [ key ] ) , opts ) ;
if ( ! delegated && prev _value ) {
// Listening to same event but different handler -> our handle function below takes care of this
// If we were to remove and add listeners in this case, it could happen that the event is "swallowed"
// (the browser seems to not know yet that a new one exists now) and doesn't reach the handler
// https://github.com/sveltejs/svelte/issues/11903
if ( value != null ) continue ;
element . removeEventListener ( event _name , current [ event _handle _key ] , opts ) ;
current [ event _handle _key ] = null ;
}
if ( value != null ) {
if ( ! delegated ) {
// we use `addEventListener` here because these events are not delegated
/ * *
* @ this { any }
* @ param { Event } evt
* /
function handle ( evt ) {
current [ key ] . call ( this , evt ) ;
}
if ( ! prev ) {
events . push ( [
key ,
value ,
( ) => ( next [ key ] = create _event ( event _name , element , value , opts ) )
( ) => ( current[ event _handle _ key] = create _event ( event _name , element , handl e, opts ) )
] ) ;
} else {
next[ key] = create _event ( event _name , element , valu e, opts ) ;
current[ event _handle _ key] = create _event ( event _name , element , handl e, opts ) ;
}
} else {
// @ts-ignore
@ -252,7 +271,7 @@ export function set_attributes(element, prev, next, lowercase_attributes, css_ha
effect ( ( ) => {
if ( ! element . isConnected ) return ;
for ( const [ key , value , evt ] of events ) {
if ( nex t[ key ] === value ) {
if ( curren t[ key ] === value ) {
evt ( ) ;
}
}
@ -261,7 +280,7 @@ export function set_attributes(element, prev, next, lowercase_attributes, css_ha
} ) ;
}
return nex t;
return curren t;
}
/ * *