From 17b2f6215deee4153d029573e4c3dc9f95ce2e4c Mon Sep 17 00:00:00 2001
From: Hunter Johnston <64506580+huntabyte@users.noreply.github.com>
Date: Thu, 2 May 2024 05:14:07 -0400
Subject: [PATCH] fix: `event.currentTarget` always being equal to
`event.target` (#11419)
fixes #11328
---
.../src/internal/client/dom/elements/events.js | 18 +++++++++---------
.../event-prop-current-target/_config.js | 12 ++++++++++++
.../event-prop-current-target/main.svelte | 13 +++++++++++++
3 files changed, 34 insertions(+), 9 deletions(-)
create mode 100644 packages/svelte/tests/runtime-runes/samples/event-prop-current-target/_config.js
create mode 100644 packages/svelte/tests/runtime-runes/samples/event-prop-current-target/main.svelte
diff --git a/packages/svelte/src/internal/client/dom/elements/events.js b/packages/svelte/src/internal/client/dom/elements/events.js
index 536b1c0442..b030996fbc 100644
--- a/packages/svelte/src/internal/client/dom/elements/events.js
+++ b/packages/svelte/src/internal/client/dom/elements/events.js
@@ -122,22 +122,22 @@ export function handle_event_propagation(handler_element, event) {
}
});
- /** @param {Element} current_target */
- function next(current_target) {
+ /** @param {Element} next_target */
+ function next(next_target) {
+ current_target = next_target;
/** @type {null | Element} */
- var parent_element =
- current_target.parentNode || /** @type {any} */ (current_target).host || null;
+ var parent_element = next_target.parentNode || /** @type {any} */ (next_target).host || null;
try {
// @ts-expect-error
- var delegated = current_target['__' + event_name];
+ var delegated = next_target['__' + event_name];
- if (delegated !== undefined && !(/** @type {any} */ (current_target).disabled)) {
+ if (delegated !== undefined && !(/** @type {any} */ (next_target).disabled)) {
if (is_array(delegated)) {
var [fn, ...data] = delegated;
- fn.apply(current_target, [event, ...data]);
+ fn.apply(next_target, [event, ...data]);
} else {
- delegated.call(current_target, event);
+ delegated.call(next_target, event);
}
}
} finally {
@@ -145,7 +145,7 @@ export function handle_event_propagation(handler_element, event) {
!event.cancelBubble &&
parent_element !== handler_element &&
parent_element !== null &&
- current_target !== handler_element
+ next_target !== handler_element
) {
next(parent_element);
}
diff --git a/packages/svelte/tests/runtime-runes/samples/event-prop-current-target/_config.js b/packages/svelte/tests/runtime-runes/samples/event-prop-current-target/_config.js
new file mode 100644
index 0000000000..f6f5c3b7d9
--- /dev/null
+++ b/packages/svelte/tests/runtime-runes/samples/event-prop-current-target/_config.js
@@ -0,0 +1,12 @@
+import { test } from '../../test';
+
+export default test({
+ async test({ assert, target, logs }) {
+ const [s1] = target.querySelectorAll('span');
+
+ s1?.click();
+ await Promise.resolve();
+
+ assert.deepEqual(logs, [false]);
+ }
+});
diff --git a/packages/svelte/tests/runtime-runes/samples/event-prop-current-target/main.svelte b/packages/svelte/tests/runtime-runes/samples/event-prop-current-target/main.svelte
new file mode 100644
index 0000000000..60fbe8baeb
--- /dev/null
+++ b/packages/svelte/tests/runtime-runes/samples/event-prop-current-target/main.svelte
@@ -0,0 +1,13 @@
+
+
+
+