@@ -141,12 +141,7 @@ export function delegate(events) {
141
141
}
142
142
}
143
143
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 too 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 ;
144
+ let event_propagation_root = new WeakMap ( ) ;
150
145
151
146
/**
152
147
* @this {EventTarget}
@@ -160,16 +155,13 @@ export function handle_event_propagation(event) {
160
155
var path = event . composedPath ?. ( ) || [ ] ;
161
156
var current_target = /** @type {null | Element } */ ( path [ 0 ] || event . target ) ;
162
157
163
- last_propagated_event = event ;
164
-
165
158
// composedPath contains list of nodes the event has propagated through.
166
- // We check __root to skip all nodes below it in case this is a
167
- // parent of the __root node, which indicates that there's nested
159
+ // We check to skip all nodes below it in case this is a
160
+ // parent of the event_propagation_root node, which indicates that there's nested
168
161
// mounted apps. In this case we don't want to trigger events multiple times.
169
162
var path_idx = 0 ;
170
163
171
- // @ts -expect-error is added below
172
- var handled_at = event . __root ;
164
+ var handled_at = event_propagation_root . get ( event ) ;
173
165
174
166
if ( handled_at ) {
175
167
var at_idx = path . indexOf ( handled_at ) ;
@@ -180,8 +172,7 @@ export function handle_event_propagation(event) {
180
172
// This is the fallback document listener or a window listener, but the event was already handled
181
173
// -> ignore, but set handle_at to document/window so that we're resetting the event
182
174
// chain in case someone manually dispatches the same event object again.
183
- // @ts -expect-error
184
- event . __root = handler_element ;
175
+ event_propagation_root . set ( event , handler_element ) ;
185
176
return ;
186
177
}
187
178
@@ -285,8 +276,7 @@ export function handle_event_propagation(event) {
285
276
throw throw_error ;
286
277
}
287
278
} finally {
288
- // @ts -expect-error is used above
289
- event . __root = handler_element ;
279
+ event_propagation_root . set ( event , handler_element ) ;
290
280
// @ts -ignore remove proxy on currentTarget
291
281
delete event . currentTarget ;
292
282
set_active_reaction ( previous_reaction ) ;
0 commit comments