pull/11810/head
Dominic Gannaway 2 years ago
parent 99dccc072f
commit 577284b310

@ -48,7 +48,7 @@ export function create_event(event_name, dom, handler, options) {
handle_event_propagation(dom, event); handle_event_propagation(dom, event);
} }
if (!event.cancelBubble) { if (!event.cancelBubble) {
return yield_event_updates(() => handler.call(this, event)); return yield_event_updates(() => handler.call(this, event), true);
} }
} }
@ -204,7 +204,7 @@ export function handle_event_propagation(handler_element, event) {
} }
try { try {
yield_event_updates(() => next(/** @type {Element} */ (current_target))); yield_event_updates(() => next(/** @type {Element} */ (current_target)), true);
} finally { } finally {
// @ts-expect-error is used above // @ts-expect-error is used above
event.__root = handler_element; event.__root = handler_element;

@ -757,17 +757,17 @@ let prev_event_type;
/** /**
* @param {{(): void;(): any;}} fn * @param {{(): void;(): any;}} fn
*/ */
export function yield_event_updates(fn) { export function yield_event_updates(fn, flush_between_events = false) {
const event = window.event; const event = window.event;
const previous_scheduler_mode = current_scheduler_mode; const previous_scheduler_mode = current_scheduler_mode;
// If we're calling yield_updates and there is already an active yield in progress (`is_yield_task_active`) // If we're calling yield_updates and there is already an active yield in progress (`is_yield_task_active`)
// and it has a different event type, then it's likely that a new event is about to occur that might try and read from the UI. // and it has a different event type, then it's likely that a new event is about to occur that might try and read from the UI.
// Additionally, we might be dealing with a case where we explicitly want to flush if `event.isTrusted` is true and // Additionally, we might be dealing with a case where we explicitly want to flush if `event.isTrusted` is true and
// `is_yield_task_queued`, for example if we had an event like `submit`, that occured because of a `click`. // `flush_between_events` is enabled, for example if we had an event like `submit`, that occured because of a `click`.
if ( if (
previous_scheduler_mode !== FLUSH_YIELD && previous_scheduler_mode !== FLUSH_YIELD &&
((is_yield_task_active && prev_event_type !== event?.type) || ((is_yield_task_active && prev_event_type !== event?.type) ||
(is_yield_task_queued && event?.isTrusted)) (is_yield_task_queued && flush_between_events && event?.isTrusted))
) { ) {
flush_sync(); flush_sync();
} }

Loading…
Cancel
Save