diff --git a/packages/svelte/src/internal/client/dom/blocks/boundary.js b/packages/svelte/src/internal/client/dom/blocks/boundary.js index 48d5855470..a194b093e7 100644 --- a/packages/svelte/src/internal/client/dom/blocks/boundary.js +++ b/packages/svelte/src/internal/client/dom/blocks/boundary.js @@ -44,7 +44,7 @@ export let active_boundary = null; export function set_active_boundary(boundary) { active_boundary = boundary; } -class Boundary { +export class Boundary { /** @type {Boundary | null} */ #parent; @@ -54,6 +54,12 @@ class Boundary { /** @type {Set<() => void>} */ #callbacks = new Set(); + /** @type {Effect[]} */ + #render_effects = []; + + /** @type {Effect[]} */ + #effects = []; + /** * @param {TemplateNode} node * @param {{ @@ -90,12 +96,6 @@ class Boundary { var hydrate_open = hydrate_node; var is_creating_fallback = false; - /** @type {Effect[]} */ - var render_effects = []; - - /** @type {Effect[]} */ - var effects = []; - var keep_pending_snippet = false; /** @@ -156,7 +156,7 @@ class Boundary { boundary_effect.f ^= BOUNDARY_SUSPENDED; } - for (const e of render_effects) { + for (const e of this.#render_effects) { try { if (check_dirtiness(e)) { update_effect(e); @@ -180,7 +180,7 @@ class Boundary { offscreen_fragment = null; } - for (const e of effects) { + for (const e of this.#effects) { try { if (check_dirtiness(e)) { update_effect(e); @@ -270,12 +270,12 @@ class Boundary { } if (input === ADD_RENDER_EFFECT) { - render_effects.push(payload); + this.#render_effects.push(payload); return; } if (input === ADD_EFFECT) { - effects.push(payload); + this.#effects.push(payload); return; } @@ -370,6 +370,9 @@ class Boundary { reset_is_throwing_error(); }, flags); + // @ts-expect-error + this.#effect.fn.boundary = this; + if (hydrating) { anchor = hydrate_node; } @@ -405,6 +408,11 @@ class Boundary { add_callback(fn) { this.#callbacks.add(fn); } + + /** @param {Effect} effect */ + add_effect(effect) { + ((effect.f & RENDER_EFFECT) !== 0 ? this.#render_effects : this.#effects).push(effect); + } } const ASYNC_INCREMENT = Symbol(); @@ -526,15 +534,6 @@ function exit() { set_component_context(null); } -/** - * @param {Effect} boundary - * @param {Effect} effect - */ -export function add_boundary_effect(boundary, effect) { - // @ts-ignore - boundary.fn((effect.f & RENDER_EFFECT) !== 0 ? ADD_RENDER_EFFECT : ADD_EFFECT, effect); -} - /** * @param {Effect} boundary */ diff --git a/packages/svelte/src/internal/client/runtime.js b/packages/svelte/src/internal/client/runtime.js index 8016eeb9b2..706b8da25b 100644 --- a/packages/svelte/src/internal/client/runtime.js +++ b/packages/svelte/src/internal/client/runtime.js @@ -50,7 +50,7 @@ import { set_component_context, set_dev_current_component_function } from './context.js'; -import { add_boundary_effect, commit_boundary } from './dom/blocks/boundary.js'; +import { Boundary, commit_boundary } from './dom/blocks/boundary.js'; import * as w from './warnings.js'; const FLUSH_MICROTASK = 0; @@ -812,7 +812,7 @@ export function schedule_effect(signal) { * * @param {Effect} effect * @param {Effect[]} collected_effects - * @param {Effect} [boundary] + * @param {Boundary} [boundary] * @returns {void} */ function process_effects(effect, collected_effects, boundary) { @@ -828,9 +828,10 @@ function process_effects(effect, collected_effects, boundary) { if (!is_skippable_branch && (flags & INERT) === 0) { if (boundary !== undefined && (flags & (BLOCK_EFFECT | BRANCH_EFFECT)) === 0) { // Inside a boundary, defer everything except block/branch effects - add_boundary_effect(/** @type {Effect} */ (boundary), current_effect); + boundary.add_effect(current_effect); } else if ((flags & BOUNDARY_EFFECT) !== 0) { - process_effects(current_effect, collected_effects, current_effect); + // @ts-expect-error + process_effects(current_effect, collected_effects, current_effect.fn.boundary); if ((current_effect.f & BOUNDARY_SUSPENDED) === 0) { // no more async work to happen