pull/11706/head
Dominic Gannaway 2 years ago
parent 2e82ecce7a
commit ab75c6d49c

@ -1,6 +1,6 @@
import { render_effect } from '../../reactivity/effects.js';
import { all_registered_events, root_event_handles } from '../../render.js';
import { FLUSH_YIELD, current_scheduler_mode, set_schedule_mode } from '../../runtime.js';
import { yield_updates } from '../../runtime.js';
import { define_property, is_array } from '../../utils.js';
import { hydrating } from '../hydration.js';
@ -181,12 +181,9 @@ export function handle_event_propagation(handler_element, event) {
}
}
const previous_scheduler_mode = current_scheduler_mode;
try {
set_schedule_mode(FLUSH_YIELD);
next(current_target);
yield_updates(() => next(/** @type {Element} */ (current_target)))
} finally {
set_schedule_mode(previous_scheduler_mode);
// @ts-expect-error is used above
event.__root = handler_element;
// @ts-expect-error is used above

@ -34,7 +34,7 @@ export const FLUSH_YIELD = 2;
/** @param {WeakSet<Error>} value */
const handled_errors = new WeakSet();
// Used for controlling the flush of effects.
export let current_scheduler_mode = FLUSH_MICROTASK;
let current_scheduler_mode = FLUSH_MICROTASK;
// Used for handling scheduling
let is_micro_task_queued = false;
let is_yield_task_queued = false;
@ -42,13 +42,6 @@ let is_yield_task_queued = false;
export let is_flushing_effect = false;
export let is_destroying_effect = false;
/**
* @param {number} value
*/
export function set_schedule_mode(value) {
current_scheduler_mode = value;
}
/** @param {boolean} value */
export function set_is_flushing_effect(value) {
is_flushing_effect = value;
@ -729,6 +722,19 @@ function process_effects(effect, collected_effects) {
}
}
/**
* @param {{ (): void; (): any; }} fn
*/
export function yield_updates(fn) {
const previous_scheduler_mode = current_scheduler_mode;
try {
current_scheduler_mode = FLUSH_YIELD;
return fn();
} finally {
current_scheduler_mode = previous_scheduler_mode;
}
}
/**
* Internal version of `flushSync` with the option to not flush previous effects.
* Returns the result of the passed function, if given.

Loading…
Cancel
Save