fix: ensure event currentTarget is reset after propagation logic (#13042)

* fix: ensure event currentTarget is reset after propgation logic

* fix: ensure event currentTarget is reset after propgation logic
pull/13057/head
Dominic Gannaway 4 months ago committed by GitHub
parent e860547cb6
commit 9cb9692aea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: ensure event currentTarget is reset after propagation logic

@ -3,7 +3,6 @@ import { teardown } from '../../reactivity/effects.js';
import { define_property, is_array } from '../../../shared/utils.js';
import { hydrating } from '../hydration.js';
import { queue_micro_task } from '../task.js';
import { dev_current_component_function } from '../../runtime.js';
import { FILENAME } from '../../../../constants.js';
import * as w from '../../warnings.js';
@ -273,8 +272,8 @@ export function handle_event_propagation(event) {
} finally {
// @ts-expect-error is used above
event.__root = handler_element;
// @ts-expect-error is used above
current_target = handler_element;
// @ts-ignore remove proxy on currentTarget
delete event.currentTarget;
}
}

@ -0,0 +1,11 @@
import { test } from '../../test';
export default test({
async test({ assert, target, logs }) {
const btn = target.querySelector('button');
btn?.click();
await Promise.resolve();
assert.deepEqual(logs, ['#app', true, 'document', true]);
}
});

@ -0,0 +1,22 @@
<script>
$effect(() => {
const doc_listener = (e) => {
console.log('document', e.currentTarget === document);
}
document.addEventListener('click', doc_listener);
document.getElementById('app')?.addEventListener('click', (e) => {
console.log('#app', e.currentTarget === document.getElementById('app'));
});
return () => {
document.removeEventListener('click', doc_listener);
};
});
function onclick() {}
</script>
<div id="app">
<button {onclick}>click me</button>
</div>
Loading…
Cancel
Save