diff --git a/packages/svelte/src/internal/client/dom/blocks/async.js b/packages/svelte/src/internal/client/dom/blocks/async.js index 109a928222..fe34167d7c 100644 --- a/packages/svelte/src/internal/client/dom/blocks/async.js +++ b/packages/svelte/src/internal/client/dom/blocks/async.js @@ -1,7 +1,7 @@ /** @import { Effect, TemplateNode, Value } from '#client' */ -/** @import { Fork } from '../../reactivity/batch.js' */ +/** @import { Batch } from '../../reactivity/batch.js' */ import { async_derived } from '../../reactivity/deriveds.js'; -import { active_fork } from '../../reactivity/batch.js'; +import { current_batch } from '../../reactivity/batch.js'; import { active_effect, schedule_effect } from '../../runtime.js'; import { capture } from './boundary.js'; @@ -13,7 +13,7 @@ import { capture } from './boundary.js'; export function async(node, expressions, fn) { // TODO handle hydration - var fork = /** @type {Fork} */ (active_fork); + var batch = /** @type {Batch} */ (current_batch); var effect = /** @type {Effect} */ (active_effect); var restore = capture(); @@ -22,7 +22,7 @@ export function async(node, expressions, fn) { restore(); fn(node, ...result); - fork.run(() => { + batch.run(() => { schedule_effect(effect); }); }); diff --git a/packages/svelte/src/internal/client/dom/blocks/boundary.js b/packages/svelte/src/internal/client/dom/blocks/boundary.js index 6150a31b28..4979a4179f 100644 --- a/packages/svelte/src/internal/client/dom/blocks/boundary.js +++ b/packages/svelte/src/internal/client/dom/blocks/boundary.js @@ -24,7 +24,7 @@ import { queue_boundary_micro_task } from '../task.js'; import * as e from '../../../shared/errors.js'; import { DEV } from 'esm-env'; import { from_async_derived, set_from_async_derived } from '../../reactivity/deriveds.js'; -import { Fork } from '../../reactivity/batch.js'; +import { Batch } from '../../reactivity/batch.js'; /** * @typedef {{ @@ -115,7 +115,7 @@ export class Boundary { // boundary, and hydrate accordingly queueMicrotask(() => { this.#main_effect = this.#run(() => { - Fork.ensure(); + Batch.ensure(); return branch(() => this.#children(this.#anchor)); }); diff --git a/packages/svelte/src/internal/client/dom/blocks/each.js b/packages/svelte/src/internal/client/dom/blocks/each.js index 48c75df275..cb0d45e1ed 100644 --- a/packages/svelte/src/internal/client/dom/blocks/each.js +++ b/packages/svelte/src/internal/client/dom/blocks/each.js @@ -1,5 +1,5 @@ /** @import { EachItem, EachState, Effect, MaybeSource, Source, TemplateNode, TransitionManager, Value } from '#client' */ -/** @import { Fork } from '../../reactivity/batch.js'; */ +/** @import { Batch } from '../../reactivity/batch.js'; */ import { EACH_INDEX_REACTIVE, EACH_IS_ANIMATED, @@ -40,7 +40,7 @@ import { queue_micro_task } from '../task.js'; import { active_effect, get } from '../../runtime.js'; import { DEV } from 'esm-env'; import { derived_safe_equal } from '../../reactivity/deriveds.js'; -import { active_fork } from '../../reactivity/batch.js'; +import { current_batch } from '../../reactivity/batch.js'; /** * The row of a keyed each block that is currently updating. We track this @@ -269,7 +269,7 @@ export function each(node, flags, get_collection, get_key, render_fn, fallback_f } else { if (should_defer_append()) { var keys = new Set(); - var fork = /** @type {Fork} */ (active_fork); + var batch = /** @type {Batch} */ (current_batch); for (i = 0; i < length; i += 1) { value = array[i]; @@ -305,11 +305,11 @@ export function each(node, flags, get_collection, get_key, render_fn, fallback_f for (const [key, item] of state.items) { if (!keys.has(key)) { - fork.skipped_effects.add(item.e); + batch.skipped_effects.add(item.e); } } - fork.add_callback(commit); + batch.add_callback(commit); } else { commit(); } diff --git a/packages/svelte/src/internal/client/dom/blocks/if.js b/packages/svelte/src/internal/client/dom/blocks/if.js index 18884d5734..9a2857e9f8 100644 --- a/packages/svelte/src/internal/client/dom/blocks/if.js +++ b/packages/svelte/src/internal/client/dom/blocks/if.js @@ -1,5 +1,5 @@ /** @import { Effect, TemplateNode } from '#client' */ -/** @import { Fork } from '../../reactivity/batch.js'; */ +/** @import { Batch } from '../../reactivity/batch.js'; */ import { EFFECT_TRANSPARENT } from '#client/constants'; import { hydrate_next, @@ -12,7 +12,7 @@ import { import { block, branch, pause_effect, resume_effect } from '../../reactivity/effects.js'; import { HYDRATION_START_ELSE, UNINITIALIZED } from '../../../../constants.js'; import { create_text, should_defer_append } from '../operations.js'; -import { active_fork } from '../../reactivity/batch.js'; +import { current_batch } from '../../reactivity/batch.js'; // TODO reinstate https://github.com/sveltejs/svelte/pull/15250 @@ -126,15 +126,15 @@ export function if_block(node, fn, elseif = false) { } if (defer) { - var fork = /** @type {Fork} */ (active_fork); + var batch = /** @type {Batch} */ (current_batch); const skipped = condition ? alternate_effect : consequent_effect; if (skipped !== null) { // TODO need to do this for other kinds of blocks - fork.skipped_effects.add(skipped); + batch.skipped_effects.add(skipped); } - fork.add_callback(commit); + batch.add_callback(commit); } else { commit(); } diff --git a/packages/svelte/src/internal/client/dom/blocks/key.js b/packages/svelte/src/internal/client/dom/blocks/key.js index 52dd5cc324..0023764e1b 100644 --- a/packages/svelte/src/internal/client/dom/blocks/key.js +++ b/packages/svelte/src/internal/client/dom/blocks/key.js @@ -1,12 +1,12 @@ /** @import { Effect, TemplateNode } from '#client' */ -/** @import { Fork } from '../../reactivity/batch.js'; */ +/** @import { Batch } from '../../reactivity/batch.js'; */ import { UNINITIALIZED } from '../../../../constants.js'; import { block, branch, pause_effect } from '../../reactivity/effects.js'; import { not_equal, safe_not_equal } from '../../reactivity/equality.js'; import { is_runes } from '../../context.js'; import { hydrate_next, hydrate_node, hydrating } from '../hydration.js'; import { create_text, should_defer_append } from '../operations.js'; -import { active_fork } from '../../reactivity/batch.js'; +import { current_batch } from '../../reactivity/batch.js'; /** * @template V @@ -66,7 +66,7 @@ export function key_block(node, get_key, render_fn) { pending_effect = branch(() => render_fn(target)); if (defer) { - /** @type {Fork} */ (active_fork).add_callback(commit); + /** @type {Batch} */ (current_batch).add_callback(commit); } else { commit(); } diff --git a/packages/svelte/src/internal/client/dom/blocks/svelte-component.js b/packages/svelte/src/internal/client/dom/blocks/svelte-component.js index dd07d7716f..f16da9c427 100644 --- a/packages/svelte/src/internal/client/dom/blocks/svelte-component.js +++ b/packages/svelte/src/internal/client/dom/blocks/svelte-component.js @@ -1,8 +1,8 @@ /** @import { TemplateNode, Dom, Effect } from '#client' */ -/** @import { Fork } from '../../reactivity/batch.js'; */ +/** @import { Batch } from '../../reactivity/batch.js'; */ import { EFFECT_TRANSPARENT } from '#client/constants'; import { block, branch, pause_effect } from '../../reactivity/effects.js'; -import { active_fork } from '../../reactivity/batch.js'; +import { current_batch } from '../../reactivity/batch.js'; import { hydrate_next, hydrate_node, hydrating } from '../hydration.js'; import { create_text, should_defer_append } from '../operations.js'; @@ -68,7 +68,7 @@ export function component(node, get_component, render_fn) { } if (defer) { - /** @type {Fork} */ (active_fork).add_callback(commit); + /** @type {Batch} */ (current_batch).add_callback(commit); } else { commit(); } diff --git a/packages/svelte/src/internal/client/reactivity/batch.js b/packages/svelte/src/internal/client/reactivity/batch.js index 73bcc17720..a4ee8fc4a0 100644 --- a/packages/svelte/src/internal/client/reactivity/batch.js +++ b/packages/svelte/src/internal/client/reactivity/batch.js @@ -5,24 +5,24 @@ import { flushSync } from '../runtime.js'; import { raf } from '../timing.js'; import { internal_set, mark_reactions, pending } from './sources.js'; -/** @type {Set} */ -const forks = new Set(); +/** @type {Set} */ +const batches = new Set(); -/** @type {Fork | null} */ -export let active_fork = null; +/** @type {Batch | null} */ +export let current_batch = null; -export function remove_active_fork() { - active_fork = null; +export function remove_current_batch() { + current_batch = null; } /** Update `$effect.pending()` */ function update_pending() { - // internal_set(pending, forks.size > 0); + // internal_set(pending, batches.size > 0); } let uid = 1; -export class Fork { +export class Batch { id = uid++; /** @type {Map} */ @@ -40,8 +40,8 @@ export class Fork { pending = 0; apply() { - if (forks.size === 1) { - // if this is the latest (and only) fork, we have nothing to do + if (batches.size === 1) { + // if this is the latest (and only) batch, we have nothing to do return noop; } @@ -56,10 +56,10 @@ export class Fork { source.v = current; } - for (const fork of forks) { - if (fork === this) continue; + for (const batch of batches) { + if (batch === this) continue; - for (const [source, previous] of fork.previous) { + for (const [source, previous] of batch.previous) { if (!current_values.has(source)) { // mark_reactions(source, DIRTY); current_values.set(source, source.v); @@ -88,19 +88,19 @@ export class Fork { } remove() { - forks.delete(this); + batches.delete(this); - for (var fork of forks) { - if (fork.id < this.id) { - // other fork is older than this + for (var batch of batches) { + if (batch.id < this.id) { + // other batch is older than this for (var source of this.previous.keys()) { - fork.previous.delete(source); + batch.previous.delete(source); } } else { - // other fork is newer than this - for (var source of fork.previous.keys()) { + // other batch is newer than this + for (var source of batch.previous.keys()) { if (this.previous.has(source)) { - fork.previous.set(source, source.v); + batch.previous.set(source, source.v); } } } @@ -113,7 +113,7 @@ export class Fork { * @param {() => void} fn */ run(fn) { - active_fork = this; + current_batch = this; fn(); } @@ -143,15 +143,15 @@ export class Fork { } static ensure() { - if (active_fork === null) { - if (forks.size === 0) { + if (current_batch === null) { + if (batches.size === 0) { raf.tick(update_pending); } - active_fork = new Fork(); - forks.add(active_fork); + current_batch = new Batch(); + batches.add(current_batch); } - return active_fork; + return current_batch; } } diff --git a/packages/svelte/src/internal/client/reactivity/deriveds.js b/packages/svelte/src/internal/client/reactivity/deriveds.js index 3e1d186fdf..b46b88fd2c 100644 --- a/packages/svelte/src/internal/client/reactivity/deriveds.js +++ b/packages/svelte/src/internal/client/reactivity/deriveds.js @@ -1,5 +1,5 @@ /** @import { Derived, Effect, Source } from '#client' */ -/** @import { Fork } from './batch.js'; */ +/** @import { Batch } from './batch.js'; */ import { DEV } from 'esm-env'; import { CLEAN, @@ -32,7 +32,7 @@ import { tracing_mode_flag } from '../../flags/index.js'; import { capture } from '../dom/blocks/boundary.js'; import { component_context } from '../context.js'; import { UNINITIALIZED } from '../../../constants.js'; -import { active_fork } from './batch.js'; +import { current_batch } from './batch.js'; /** @type {Effect | null} */ export let from_async_derived = null; @@ -124,14 +124,14 @@ export function async_derived(fn, location) { var restore = capture(); - var fork = /** @type {Fork} */ (active_fork); + var batch = /** @type {Batch} */ (current_batch); var ran = boundary.ran; if (should_suspend) { if (!ran) { boundary.increment(); } else { - fork.increment(); + batch.increment(); } } @@ -148,11 +148,11 @@ export function async_derived(fn, location) { if (!ran) { boundary.decrement(); } else { - fork.decrement(); + batch.decrement(); } } - fork.run(() => { + batch.run(() => { internal_set(signal, v); }); diff --git a/packages/svelte/src/internal/client/reactivity/effects.js b/packages/svelte/src/internal/client/reactivity/effects.js index d29d34658e..28494cec6f 100644 --- a/packages/svelte/src/internal/client/reactivity/effects.js +++ b/packages/svelte/src/internal/client/reactivity/effects.js @@ -41,7 +41,7 @@ import { get_next_sibling } from '../dom/operations.js'; import { async_derived, derived } from './deriveds.js'; import { capture } from '../dom/blocks/boundary.js'; import { component_context, dev_current_component_function } from '../context.js'; -import { active_fork, Fork } from './batch.js'; +import { current_batch, Batch } from './batch.js'; /** * @param {'$effect' | '$effect.pre' | '$inspect'} rune @@ -234,7 +234,7 @@ export function inspect_effect(fn) { * @returns {() => void} */ export function effect_root(fn) { - Fork.ensure(); + Batch.ensure(); const effect = create_effect(ROOT_EFFECT, fn, true); return () => { @@ -248,7 +248,7 @@ export function effect_root(fn) { * @returns {(options?: { outro?: boolean }) => Promise} */ export function component_root(fn) { - Fork.ensure(); + Batch.ensure(); const effect = create_effect(ROOT_EFFECT, fn, true); return (options = {}) => { @@ -343,7 +343,7 @@ export function template_effect(fn, sync = [], async = [], d = derived) { var parent = /** @type {Effect} */ (active_effect); if (async.length > 0) { - var fork = /** @type {Fork} */ (active_fork); + var batch = /** @type {Batch} */ (current_batch); var restore = capture(); Promise.all(async.map((expression) => async_derived(expression))).then((result) => { @@ -355,7 +355,7 @@ export function template_effect(fn, sync = [], async = [], d = derived) { var effect = create_template_effect(fn, [...sync.map(d), ...result]); - fork.run(() => { + batch.run(() => { schedule_effect(effect); }); }); diff --git a/packages/svelte/src/internal/client/reactivity/sources.js b/packages/svelte/src/internal/client/reactivity/sources.js index 9879932945..d8b609859f 100644 --- a/packages/svelte/src/internal/client/reactivity/sources.js +++ b/packages/svelte/src/internal/client/reactivity/sources.js @@ -34,7 +34,7 @@ import * as e from '../errors.js'; import { legacy_mode_flag, tracing_mode_flag } from '../../flags/index.js'; import { get_stack } from '../dev/tracing.js'; import { component_context, is_runes } from '../context.js'; -import { Fork } from './batch.js'; +import { Batch } from './batch.js'; import { proxy } from '../proxy.js'; import { execute_derived } from './deriveds.js'; @@ -169,8 +169,8 @@ export function internal_set(source, value) { source.v = value; - const fork = Fork.ensure(); - fork.capture(source, old_value); + const batch = Batch.ensure(); + batch.capture(source, old_value); if (DEV && tracing_mode_flag) { source.updated = get_stack('UpdatedAt'); diff --git a/packages/svelte/src/internal/client/runtime.js b/packages/svelte/src/internal/client/runtime.js index 357c62aaf0..10ec5c536d 100644 --- a/packages/svelte/src/internal/client/runtime.js +++ b/packages/svelte/src/internal/client/runtime.js @@ -50,7 +50,7 @@ import { import { Boundary } from './dom/blocks/boundary.js'; import * as w from './warnings.js'; import { is_firefox } from './dom/operations.js'; -import { active_fork, Fork, remove_active_fork } from './reactivity/batch.js'; +import { current_batch, Batch, remove_current_batch } from './reactivity/batch.js'; // Used for DEV time error handling /** @param {WeakSet} value */ @@ -683,7 +683,7 @@ function infinite_loop_guard() { function flush_queued_root_effects() { var was_updating_effect = is_updating_effect; - var fork = /** @type {Fork} */ (active_fork); + var batch = /** @type {Batch} */ (current_batch); try { var flush_count = 0; @@ -694,7 +694,7 @@ function flush_queued_root_effects() { infinite_loop_guard(); } - var revert = fork.apply(); + var revert = batch.apply(); /** @type {Effect[]} */ var async_effects = []; @@ -720,8 +720,8 @@ function flush_queued_root_effects() { process_effects(root, async_effects, render_effects, effects); } - if (async_effects.length === 0 && fork.pending === 0) { - fork.commit(); + if (async_effects.length === 0 && batch.pending === 0) { + batch.commit(); flush_queued_effects(render_effects); flush_queued_effects(effects); } @@ -791,18 +791,18 @@ export function schedule_effect(signal) { if (!is_flushing) { is_flushing = true; queueMicrotask(() => { - if (active_fork === null) { + if (current_batch === null) { // a flushSync happened in the meantime return; } flush_queued_root_effects(); - if (active_fork?.pending === 0) { - active_fork.remove(); + if (current_batch?.pending === 0) { + current_batch.remove(); } - remove_active_fork(); + remove_current_batch(); }); } @@ -843,14 +843,14 @@ export function schedule_effect(signal) { */ function process_effects(root, async_effects, render_effects, effects) { var effect = root.first; - var fork = /** @type {Fork} */ (active_fork); + var batch = /** @type {Batch} */ (current_batch); while (effect !== null) { var flags = effect.f; var is_branch = (flags & BRANCH_EFFECT) !== 0; var is_skippable_branch = is_branch && (flags & CLEAN) !== 0; - var skip = is_skippable_branch || (flags & INERT) !== 0 || fork.skipped_effects.has(effect); + var skip = is_skippable_branch || (flags & INERT) !== 0 || batch.skipped_effects.has(effect); if (!skip) { if ((flags & EFFECT_ASYNC) !== 0) { @@ -867,7 +867,7 @@ function process_effects(root, async_effects, render_effects, effects) { } } else if ((flags & RENDER_EFFECT) !== 0) { if (is_branch) { - // TODO clean branch later, if fork is settled + // TODO clean branch later, if batch is settled // current_effect.f ^= CLEAN; } else { render_effects.push(effect); @@ -904,7 +904,7 @@ function process_effects(root, async_effects, render_effects, effects) { export function flushSync(fn) { var result; - Fork.ensure(); + Batch.ensure(); if (fn) { is_flushing = true; @@ -920,11 +920,11 @@ export function flushSync(fn) { flush_tasks(); } - if (active_fork?.pending === 0) { - active_fork.remove(); + if (current_batch?.pending === 0) { + current_batch.remove(); } - remove_active_fork(); + remove_current_batch(); return /** @type {T} */ (result); }