Skip to content

Commit f747c41

Browse files
authored
chore: tweak effect self invalidation logic (#15275)
Also make sure events dispatched via transition/animation logic runs outside event context Related to #15262
1 parent 5e52825 commit f747c41

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

.changeset/rare-hounds-wave.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
chore: tweak effect self invalidation logic, run transition dispatches without reactive context

packages/svelte/src/internal/client/dom/elements/transitions.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,17 @@ import { current_each_item } from '../blocks/each.js';
1414
import { TRANSITION_GLOBAL, TRANSITION_IN, TRANSITION_OUT } from '../../../../constants.js';
1515
import { BLOCK_EFFECT, EFFECT_RAN, EFFECT_TRANSPARENT } from '../../constants.js';
1616
import { queue_micro_task } from '../task.js';
17+
import { without_reactive_context } from './bindings/shared.js';
1718

1819
/**
1920
* @param {Element} element
2021
* @param {'introstart' | 'introend' | 'outrostart' | 'outroend'} type
2122
* @returns {void}
2223
*/
2324
function dispatch_event(element, type) {
24-
element.dispatchEvent(new CustomEvent(type));
25+
without_reactive_context(() => {
26+
element.dispatchEvent(new CustomEvent(type));
27+
});
2528
}
2629

2730
/**

packages/svelte/src/internal/client/runtime.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -370,22 +370,18 @@ export function handle_error(error, effect, previous_effect, component_context)
370370
/**
371371
* @param {Value} signal
372372
* @param {Effect} effect
373-
* @param {number} [depth]
373+
* @param {boolean} [root]
374374
*/
375-
function schedule_possible_effect_self_invalidation(signal, effect, depth = 0) {
375+
function schedule_possible_effect_self_invalidation(signal, effect, root = true) {
376376
var reactions = signal.reactions;
377377
if (reactions === null) return;
378378

379379
for (var i = 0; i < reactions.length; i++) {
380380
var reaction = reactions[i];
381381
if ((reaction.f & DERIVED) !== 0) {
382-
schedule_possible_effect_self_invalidation(
383-
/** @type {Derived} */ (reaction),
384-
effect,
385-
depth + 1
386-
);
382+
schedule_possible_effect_self_invalidation(/** @type {Derived} */ (reaction), effect, false);
387383
} else if (effect === reaction) {
388-
if (depth === 0) {
384+
if (root) {
389385
set_signal_status(reaction, DIRTY);
390386
} else if ((reaction.f & CLEAN) !== 0) {
391387
set_signal_status(reaction, MAYBE_DIRTY);
@@ -458,6 +454,8 @@ export function update_reaction(reaction) {
458454
if (
459455
is_runes() &&
460456
untracked_writes !== null &&
457+
!untracking &&
458+
deps !== null &&
461459
(reaction.f & (DERIVED | MAYBE_DIRTY | DIRTY)) === 0
462460
) {
463461
for (i = 0; i < /** @type {Source[]} */ (untracked_writes).length; i++) {

0 commit comments

Comments
 (0)