@@ -141,12 +141,7 @@ 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 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 ( ) ;
150145
151146/**
152147 * @this {EventTarget}
@@ -160,16 +155,14 @@ export function handle_event_propagation(event) {
160155 var path = event . composedPath ?. ( ) || [ ] ;
161156 var current_target = /** @type {null | Element } */ ( path [ 0 ] || event . target ) ;
162157
163- last_propagated_event = event ;
164-
165158 // 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
168161 // mounted apps. In this case we don't want to trigger events multiple times.
169162 var path_idx = 0 ;
170163
171164 // @ts -expect-error is added below
172- var handled_at = event . __root ;
165+ var handled_at = event_propagation_root . get ( event ) ;
173166
174167 if ( handled_at ) {
175168 var at_idx = path . indexOf ( handled_at ) ;
@@ -181,7 +174,7 @@ export function handle_event_propagation(event) {
181174 // -> ignore, but set handle_at to document/window so that we're resetting the event
182175 // chain in case someone manually dispatches the same event object again.
183176 // @ts -expect-error
184- event . __root = handler_element ;
177+ event_propagation_root . set ( event , handler_element ) ;
185178 return ;
186179 }
187180
@@ -286,7 +279,7 @@ export function handle_event_propagation(event) {
286279 }
287280 } finally {
288281 // @ts -expect-error is used above
289- event . __root = handler_element ;
282+ event_propagation_root . set ( event , handler_element ) ;
290283 // @ts -ignore remove proxy on currentTarget
291284 delete event . currentTarget ;
292285 set_active_reaction ( previous_reaction ) ;
0 commit comments