better changeset, use owner_document, comment

pull/10611/head
Simon H 3 years ago committed by GitHub
parent 4779f150a8
commit ff1ae81343
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -2,4 +2,4 @@
"svelte": patch "svelte": patch
--- ---
fix: trigger again when window listener already handled fix: prevent window listeners from triggering events twice

@ -1383,6 +1383,7 @@ export function delegate(events) {
* @returns {void} * @returns {void}
*/ */
function handle_event_propagation(handler_element, event) { function handle_event_propagation(handler_element, event) {
const owner_document = handler_element.ownerDocument;
const event_name = event.type; const event_name = event.type;
const path = event.composedPath?.() || []; const path = event.composedPath?.() || [];
let current_target = /** @type {null | Element} */ (path[0] || event.target); let current_target = /** @type {null | Element} */ (path[0] || event.target);
@ -1402,9 +1403,11 @@ function handle_event_propagation(handler_element, event) {
const handled_at = event.__root; const handled_at = event.__root;
if (handled_at) { if (handled_at) {
const at_idx = path.indexOf(handled_at); const at_idx = path.indexOf(handled_at);
// @ts-ignore if (
if (at_idx !== -1 && (handler_element === document || handler_element === window)) { at_idx !== -1 &&
// This is the fallback document/window listener but the event was already handled (handler_element === owner_document || handler_element === /** @type {any} */ (window))
) {
// This is the fallback document listener or a window listener, but the event was already handled
// -> ignore, but set handle_at to document/window so that we're resetting the event // -> ignore, but set handle_at to document/window so that we're resetting the event
// chain in case someone manually dispatches the same event object again. // chain in case someone manually dispatches the same event object again.
// @ts-expect-error // @ts-expect-error
@ -1434,8 +1437,7 @@ function handle_event_propagation(handler_element, event) {
define_property(event, 'currentTarget', { define_property(event, 'currentTarget', {
configurable: true, configurable: true,
get() { get() {
// TODO: ensure correct document? return current_target || owner_document;
return current_target || document;
} }
}); });

Loading…
Cancel
Save