Skip to content

Commit

Permalink
fix: fire delegated events on target even it was disabled in the mean…
Browse files Browse the repository at this point in the history
…time (#15319)

They DOM could've been updated already by the time the event bubbling logic is reached, so the target element itself could not be notified of the event because it is marked as disabled. But the target could not have been disabled because it emits the event in the first place, so we emit regardless.

No test because not reproducible in jsdom environment.

Fixes #15256
  • Loading branch information
dummdidumm authored Feb 17, 2025
1 parent 0d5d9ab commit 9091e7e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/wicked-apples-yawn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: fire delegated events on target even it was disabled in the meantime
8 changes: 7 additions & 1 deletion packages/svelte/src/internal/client/dom/elements/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,13 @@ export function handle_event_propagation(event) {
// @ts-expect-error
var delegated = current_target['__' + event_name];

if (delegated !== undefined && !(/** @type {any} */ (current_target).disabled)) {
if (
delegated !== undefined &&
(!(/** @type {any} */ (current_target).disabled) ||
// DOM could've been updated already by the time this is reached, so we check this as well
// -> the target could not have been disabled because it emits the event in the first place
event.target === current_target)
) {
if (is_array(delegated)) {
var [fn, ...data] = delegated;
fn.apply(current_target, [event, ...data]);
Expand Down

0 comments on commit 9091e7e

Please sign in to comment.