pull/16197/head
Rich Harris 7 months ago
parent 94da28f97c
commit ee71311e9d

@ -1,7 +1,9 @@
/** @import { TemplateNode, Value } from '#client' */
/** @import { Effect, TemplateNode, Value } from '#client' */
import { async_derived } from '../../reactivity/deriveds.js';
import { capture, suspend } from './boundary.js';
import { active_fork } from '../../reactivity/forks.js';
import { active_effect, schedule_effect } from '../../runtime.js';
import { capture } from './boundary.js';
/**
* @param {TemplateNode} node
@ -11,12 +13,16 @@ import { capture, suspend } from './boundary.js';
export function async(node, expressions, fn) {
// TODO handle hydration
var fork = active_fork;
var effect = /** @type {Effect} */ (active_effect);
var restore = capture();
var unsuspend = suspend();
Promise.all(expressions.map((fn) => async_derived(fn))).then((result) => {
restore();
fn(node, ...result);
unsuspend();
fork?.run(() => {
schedule_effect(effect);
});
});
}

@ -11,7 +11,6 @@ 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_effect } from '../../runtime.js';
import { active_fork } from '../../reactivity/forks.js';
/**
@ -51,10 +50,10 @@ export function if_block(node, fn, elseif = false) {
/** @type {Effect | null} */
var pending_effect = null;
var boundary = /** @type {Effect} */ (active_effect).b;
function commit() {
if (offscreen_fragment !== null) {
// remove the anchor
/** @type {Text} */ (offscreen_fragment.lastChild).remove();
anchor.before(offscreen_fragment);
offscreen_fragment = null;
}
@ -130,7 +129,6 @@ export function if_block(node, fn, elseif = false) {
}
active_fork?.add_callback(commit);
target.remove();
} else {
commit();
}

@ -12,8 +12,7 @@ import {
set_is_destroying_effect,
set_signal_status,
untrack,
untracking,
flushSync
untracking
} from '../runtime.js';
import {
DIRTY,
@ -40,7 +39,7 @@ import { DEV } from 'esm-env';
import { define_property } from '../../shared/utils.js';
import { get_next_sibling } from '../dom/operations.js';
import { async_derived, derived } from './deriveds.js';
import { capture, suspend } from '../dom/blocks/boundary.js';
import { capture } from '../dom/blocks/boundary.js';
import { component_context, dev_current_component_function } from '../context.js';
import { active_fork } from './forks.js';

@ -29,7 +29,7 @@ export class Fork {
/** @type {Set<() => void>} */
#callbacks = new Set();
#pending = 0;
pending = 0;
apply() {
if (forks.size === 1) {
@ -108,15 +108,15 @@ export class Fork {
}
increment() {
this.#pending += 1;
this.pending += 1;
}
decrement() {
this.#pending -= 1;
this.pending -= 1;
}
settled() {
return this.#pending === 0;
return this.pending === 0;
}
/** @param {() => void} fn */

@ -776,7 +776,7 @@ export function queue_flush() {
// TODO this doesn't seem quite right — may run into
// interesting cases where there are multiple roots.
// it'll do for now though
if (active_fork?.settled()) {
if (active_fork?.pending === 0) {
active_fork.remove();
}
@ -858,7 +858,7 @@ function process_effects(root, fork) {
}
}
if (async_effects.length === 0 && (fork === null || fork.settled())) {
if (async_effects.length === 0 && (fork === null || fork.pending === 0)) {
fork?.commit();
flush_queued_effects(render_effects);
flush_queued_effects(effects);
@ -898,7 +898,7 @@ export function flushSync(fn) {
// TODO this doesn't seem quite right — may run into
// interesting cases where there are multiple roots.
// it'll do for now though
if (active_fork?.settled()) {
if (active_fork?.pending === 0) {
active_fork.remove();
}

Loading…
Cancel
Save