diff --git a/packages/svelte/src/internal/client/reactivity/batch.js b/packages/svelte/src/internal/client/reactivity/batch.js index 6b9e048391..249edbacdc 100644 --- a/packages/svelte/src/internal/client/reactivity/batch.js +++ b/packages/svelte/src/internal/client/reactivity/batch.js @@ -69,8 +69,13 @@ let last_scheduled_effect = null; let is_flushing = false; export let is_flushing_sync = false; -/** @type {Effect[] | null} */ -export let current_effects = null; +/** + * During traversal, this is an array. Newly created effects are (if not immediately + * executed) pushed to this array, rather than going through the scheduling + * rigamarole that would cause another turn of the flush loop. + * @type {Effect[] | null} + */ +export let collected_effects = null; export class Batch { /** @@ -188,7 +193,7 @@ export class Batch { this.apply(); /** @type {Effect[]} */ - var effects = (current_effects = []); + var effects = (collected_effects = []); /** @type {Effect[]} */ var render_effects = []; @@ -202,7 +207,7 @@ export class Batch { // log_inconsistent_branches(root); } - current_effects = null; + collected_effects = null; if (this.#is_deferred()) { this.#defer_effects(render_effects); @@ -643,6 +648,7 @@ function flush_effects() { is_flushing = false; last_scheduled_effect = null; + collected_effects = null; if (DEV) { for (const source of /** @type {Set} */ (source_stacks)) { @@ -848,13 +854,7 @@ export function schedule_effect(signal) { // if the effect is being scheduled because a parent (each/await/etc) block // updated an internal source, or because a branch is being unskipped, // bail out or we'll cause a second flush - if ( - is_flushing && - effect === active_effect && - (flags & BLOCK_EFFECT) !== 0 && - (flags & HEAD_EFFECT) === 0 && - (flags & REACTION_RAN) !== 0 - ) { + if (collected_effects !== null && effect === active_effect) { return; } diff --git a/packages/svelte/src/internal/client/reactivity/effects.js b/packages/svelte/src/internal/client/reactivity/effects.js index 0e8155acee..7a6694ec13 100644 --- a/packages/svelte/src/internal/client/reactivity/effects.js +++ b/packages/svelte/src/internal/client/reactivity/effects.js @@ -40,7 +40,7 @@ import { DEV } from 'esm-env'; import { define_property } from '../../shared/utils.js'; import { get_next_sibling } from '../dom/operations.js'; import { component_context, dev_current_component_function, dev_stack } from '../context.js'; -import { Batch, current_effects, schedule_effect } from './batch.js'; +import { Batch, collected_effects, schedule_effect } from './batch.js'; import { flatten, increment_pending } from './async.js'; import { without_reactive_context } from '../dom/elements/bindings/shared.js'; import { set_signal_status } from './status.js'; @@ -127,8 +127,8 @@ function create_effect(type, fn, sync) { throw e; } } else if (fn !== null) { - if (current_effects !== null) { - current_effects.push(effect); + if (collected_effects !== null) { + collected_effects.push(effect); } else { Batch.ensure(); schedule_effect(effect);