pull/16197/head
Rich Harris 8 months ago
parent ba68a937af
commit fde316fcc8

@ -79,15 +79,6 @@ export class Boundary {
/** @type {Effect} */
#effect;
/** @type {Set<() => void>} */
#callbacks = new Set();
/** @type {Effect[]} */
#render_effects = [];
/** @type {Effect[]} */
#effects = [];
/** @type {Effect | null} */
#main_effect = null;
@ -230,16 +221,6 @@ export class Boundary {
}
}
/** @param {() => void} fn */
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);
}
commit() {
if (this.#keep_pending_snippet || this.#pending_count > 0) {
return;
@ -247,19 +228,6 @@ export class Boundary {
this.suspended = false;
for (const e of this.#render_effects) {
try {
if (check_dirtiness(e)) {
update_effect(e);
}
} catch (error) {
handle_error(error, e, null, e.ctx);
}
}
for (const fn of this.#callbacks) fn();
this.#callbacks.clear();
if (this.#pending_effect) {
pause_effect(this.#pending_effect, () => {
this.#pending_effect = null;
@ -270,16 +238,6 @@ export class Boundary {
this.#anchor.before(this.#offscreen_fragment);
this.#offscreen_fragment = null;
}
for (const e of this.#effects) {
try {
if (check_dirtiness(e)) {
update_effect(e);
}
} catch (error) {
handle_error(error, e, null, e.ctx);
}
}
}
increment() {

@ -39,6 +39,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/forks.js';
/**
* The row of a keyed each block that is currently updating. We track this
@ -267,7 +268,7 @@ export function each(node, flags, get_collection, get_key, render_fn, fallback_f
fallback = branch(() => fallback_fn(anchor));
}
} else {
if (boundary !== null && should_defer_append()) {
if (active_fork !== null && should_defer_append()) {
for (i = 0; i < length; i += 1) {
value = array[i];
key = get_key(value, i);
@ -298,7 +299,7 @@ export function each(node, flags, get_collection, get_key, render_fn, fallback_f
}
}
boundary?.add_callback(commit);
active_fork?.add_callback(commit);
} else {
commit();
}

@ -12,6 +12,7 @@ import { block, branch, pause_effect, resume_effect } from '../../reactivity/eff
import { HYDRATION_START_ELSE, UNINITIALIZED } from '../../../../constants.js';
import { create_text, should_defer_append } from '../operations.js';
import { active_effect } from '../../runtime.js';
import { active_fork } from '../../reactivity/forks.js';
/**
* @param {TemplateNode} node
@ -109,7 +110,7 @@ export function if_block(node, fn, elseif = false) {
}
}
var defer = boundary !== null && should_defer_append();
var defer = active_fork !== null && should_defer_append();
var target = anchor;
if (defer) {
@ -122,7 +123,7 @@ export function if_block(node, fn, elseif = false) {
}
if (defer) {
boundary?.add_callback(commit);
active_fork?.add_callback(commit);
target.remove();
} else {
commit();

@ -6,6 +6,7 @@ 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_effect } from '../../runtime.js';
import { active_fork } from '../../reactivity/forks.js';
/**
* @template V
@ -54,7 +55,7 @@ export function key_block(node, get_key, render_fn) {
if (changed(key, (key = get_key()))) {
var target = anchor;
var defer = boundary !== null && should_defer_append();
var defer = active_fork !== null && should_defer_append();
if (defer) {
offscreen_fragment = document.createDocumentFragment();
@ -64,7 +65,7 @@ export function key_block(node, get_key, render_fn) {
pending_effect = branch(() => render_fn(target));
if (defer) {
boundary?.add_callback(commit);
active_fork?.add_callback(commit);
target.remove();
} else {
commit();

@ -1,6 +1,7 @@
/** @import { TemplateNode, Dom, Effect } from '#client' */
import { EFFECT_TRANSPARENT } from '../../constants.js';
import { block, branch, pause_effect } from '../../reactivity/effects.js';
import { active_fork } from '../../reactivity/forks.js';
import { active_effect } from '../../runtime.js';
import { hydrate_next, hydrate_node, hydrating } from '../hydration.js';
import { create_text, should_defer_append } from '../operations.js';
@ -51,7 +52,7 @@ export function component(node, get_component, render_fn) {
block(() => {
if (component === (component = get_component())) return;
var defer = boundary !== null && should_defer_append();
var defer = active_fork !== null && should_defer_append();
if (component) {
var target = anchor;
@ -69,7 +70,7 @@ export function component(node, get_component, render_fn) {
}
if (defer) {
boundary?.add_callback(commit);
active_fork?.add_callback(commit);
} else {
commit();
}

@ -28,6 +28,9 @@ export class Fork {
/** @type {Set<Effect>} */
skipped_effects = new Set();
/** @type {Set<() => void>} */
#callbacks = new Set();
#pending = 0;
apply() {
@ -118,6 +121,17 @@ export class Fork {
return this.#pending === 0;
}
/** @param {() => void} fn */
add_callback(fn) {
this.#callbacks.add(fn);
}
commit() {
for (const fn of this.#callbacks) {
fn();
}
}
static ensure() {
if (active_fork === null) {
active_fork = new Fork();

@ -862,6 +862,7 @@ function process_effects(effect, fork) {
}
if (async_effects.length === 0 && fork.settled()) {
fork.commit();
flush_queued_effects(render_effects);
flush_queued_effects(effects);
}

Loading…
Cancel
Save