chore: tweak effect self invalidation logic (#15275)

Also make sure events dispatched via transition/animation logic runs outside event context

Related to #15262
pull/15271/head
Dominic Gannaway 7 months ago committed by GitHub
parent 5e52825d60
commit f747c412f4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
chore: tweak effect self invalidation logic, run transition dispatches without reactive context

@ -14,6 +14,7 @@ import { current_each_item } from '../blocks/each.js';
import { TRANSITION_GLOBAL, TRANSITION_IN, TRANSITION_OUT } from '../../../../constants.js';
import { BLOCK_EFFECT, EFFECT_RAN, EFFECT_TRANSPARENT } from '../../constants.js';
import { queue_micro_task } from '../task.js';
import { without_reactive_context } from './bindings/shared.js';
/**
* @param {Element} element
@ -21,7 +22,9 @@ import { queue_micro_task } from '../task.js';
* @returns {void}
*/
function dispatch_event(element, type) {
element.dispatchEvent(new CustomEvent(type));
without_reactive_context(() => {
element.dispatchEvent(new CustomEvent(type));
});
}
/**

@ -370,22 +370,18 @@ export function handle_error(error, effect, previous_effect, component_context)
/**
* @param {Value} signal
* @param {Effect} effect
* @param {number} [depth]
* @param {boolean} [root]
*/
function schedule_possible_effect_self_invalidation(signal, effect, depth = 0) {
function schedule_possible_effect_self_invalidation(signal, effect, root = true) {
var reactions = signal.reactions;
if (reactions === null) return;
for (var i = 0; i < reactions.length; i++) {
var reaction = reactions[i];
if ((reaction.f & DERIVED) !== 0) {
schedule_possible_effect_self_invalidation(
/** @type {Derived} */ (reaction),
effect,
depth + 1
);
schedule_possible_effect_self_invalidation(/** @type {Derived} */ (reaction), effect, false);
} else if (effect === reaction) {
if (depth === 0) {
if (root) {
set_signal_status(reaction, DIRTY);
} else if ((reaction.f & CLEAN) !== 0) {
set_signal_status(reaction, MAYBE_DIRTY);
@ -458,6 +454,8 @@ export function update_reaction(reaction) {
if (
is_runes() &&
untracked_writes !== null &&
!untracking &&
deps !== null &&
(reaction.f & (DERIVED | MAYBE_DIRTY | DIRTY)) === 0
) {
for (i = 0; i < /** @type {Source[]} */ (untracked_writes).length; i++) {

Loading…
Cancel
Save