Skip to content

Commit

Permalink
chore: tweak effect self invalidation logic (#15275)
Browse files Browse the repository at this point in the history
Also make sure events dispatched via transition/animation logic runs outside event context

Related to #15262
  • Loading branch information
trueadm authored Feb 12, 2025
1 parent 5e52825 commit f747c41
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/rare-hounds-wave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

chore: tweak effect self invalidation logic, run transition dispatches without reactive context
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@ 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
* @param {'introstart' | 'introend' | 'outrostart' | 'outroend'} type
* @returns {void}
*/
function dispatch_event(element, type) {
element.dispatchEvent(new CustomEvent(type));
without_reactive_context(() => {
element.dispatchEvent(new CustomEvent(type));
});
}

/**
Expand Down
14 changes: 6 additions & 8 deletions packages/svelte/src/internal/client/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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++) {
Expand Down

0 comments on commit f747c41

Please sign in to comment.