Skip to content

Commit 6a1d0ea

Browse files
committed
Fix double event processing (#16522)
Firefox seems to garbage collect event objects during event propagation if no global reference to the event object is kept. That discards the __root marker set on the event object to early, leading to duplicate processing.
1 parent d82edf6 commit 6a1d0ea

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

.changeset/chilly-bananas-train.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
Fix double event processing in firefox due to event object being garbage collected (#16522)

packages/svelte/src/internal/client/dom/elements/events.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,13 @@ export function delegate(events) {
141141
}
142142
}
143143

144+
// used to store the reference to the currently propagated event
145+
// to prevent garbage collection between microtasks in Firefox
146+
// If the event object is GCed to early, the expando __root property
147+
// set on the event object is lost, causing the event delegation
148+
// to process the event twice
149+
let last_propagated_event = null;
150+
144151
/**
145152
* @this {EventTarget}
146153
* @param {Event} event
@@ -153,6 +160,8 @@ export function handle_event_propagation(event) {
153160
var path = event.composedPath?.() || [];
154161
var current_target = /** @type {null | Element} */ (path[0] || event.target);
155162

163+
last_propagated_event = event;
164+
156165
// composedPath contains list of nodes the event has propagated through.
157166
// We check __root to skip all nodes below it in case this is a
158167
// parent of the __root node, which indicates that there's nested

0 commit comments

Comments
 (0)