async-changeset
Rich Harris 7 months ago
parent ba957b625f
commit fe3b177d97

@ -44,7 +44,7 @@ export let active_boundary = null;
export function set_active_boundary(boundary) { export function set_active_boundary(boundary) {
active_boundary = boundary; active_boundary = boundary;
} }
class Boundary { export class Boundary {
/** @type {Boundary | null} */ /** @type {Boundary | null} */
#parent; #parent;
@ -54,6 +54,12 @@ class Boundary {
/** @type {Set<() => void>} */ /** @type {Set<() => void>} */
#callbacks = new Set(); #callbacks = new Set();
/** @type {Effect[]} */
#render_effects = [];
/** @type {Effect[]} */
#effects = [];
/** /**
* @param {TemplateNode} node * @param {TemplateNode} node
* @param {{ * @param {{
@ -90,12 +96,6 @@ class Boundary {
var hydrate_open = hydrate_node; var hydrate_open = hydrate_node;
var is_creating_fallback = false; var is_creating_fallback = false;
/** @type {Effect[]} */
var render_effects = [];
/** @type {Effect[]} */
var effects = [];
var keep_pending_snippet = false; var keep_pending_snippet = false;
/** /**
@ -156,7 +156,7 @@ class Boundary {
boundary_effect.f ^= BOUNDARY_SUSPENDED; boundary_effect.f ^= BOUNDARY_SUSPENDED;
} }
for (const e of render_effects) { for (const e of this.#render_effects) {
try { try {
if (check_dirtiness(e)) { if (check_dirtiness(e)) {
update_effect(e); update_effect(e);
@ -180,7 +180,7 @@ class Boundary {
offscreen_fragment = null; offscreen_fragment = null;
} }
for (const e of effects) { for (const e of this.#effects) {
try { try {
if (check_dirtiness(e)) { if (check_dirtiness(e)) {
update_effect(e); update_effect(e);
@ -270,12 +270,12 @@ class Boundary {
} }
if (input === ADD_RENDER_EFFECT) { if (input === ADD_RENDER_EFFECT) {
render_effects.push(payload); this.#render_effects.push(payload);
return; return;
} }
if (input === ADD_EFFECT) { if (input === ADD_EFFECT) {
effects.push(payload); this.#effects.push(payload);
return; return;
} }
@ -370,6 +370,9 @@ class Boundary {
reset_is_throwing_error(); reset_is_throwing_error();
}, flags); }, flags);
// @ts-expect-error
this.#effect.fn.boundary = this;
if (hydrating) { if (hydrating) {
anchor = hydrate_node; anchor = hydrate_node;
} }
@ -405,6 +408,11 @@ class Boundary {
add_callback(fn) { add_callback(fn) {
this.#callbacks.add(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(); const ASYNC_INCREMENT = Symbol();
@ -526,15 +534,6 @@ function exit() {
set_component_context(null); 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 * @param {Effect} boundary
*/ */

@ -50,7 +50,7 @@ import {
set_component_context, set_component_context,
set_dev_current_component_function set_dev_current_component_function
} from './context.js'; } 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'; import * as w from './warnings.js';
const FLUSH_MICROTASK = 0; const FLUSH_MICROTASK = 0;
@ -812,7 +812,7 @@ export function schedule_effect(signal) {
* *
* @param {Effect} effect * @param {Effect} effect
* @param {Effect[]} collected_effects * @param {Effect[]} collected_effects
* @param {Effect} [boundary] * @param {Boundary} [boundary]
* @returns {void} * @returns {void}
*/ */
function process_effects(effect, collected_effects, boundary) { 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 (!is_skippable_branch && (flags & INERT) === 0) {
if (boundary !== undefined && (flags & (BLOCK_EFFECT | BRANCH_EFFECT)) === 0) { if (boundary !== undefined && (flags & (BLOCK_EFFECT | BRANCH_EFFECT)) === 0) {
// Inside a boundary, defer everything except block/branch effects // 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) { } 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) { if ((current_effect.f & BOUNDARY_SUSPENDED) === 0) {
// no more async work to happen // no more async work to happen

Loading…
Cancel
Save