partial fix

async-changeset
Rich Harris 7 months ago
parent 9039fef709
commit e73fed368e

@ -2,8 +2,11 @@
import { import {
BOUNDARY_EFFECT, BOUNDARY_EFFECT,
DIRTY,
EFFECT_PRESERVED, EFFECT_PRESERVED,
EFFECT_RAN,
EFFECT_TRANSPARENT, EFFECT_TRANSPARENT,
MAYBE_DIRTY,
RENDER_EFFECT RENDER_EFFECT
} from '../../constants.js'; } from '../../constants.js';
import { component_context, set_component_context } from '../../context.js'; import { component_context, set_component_context } from '../../context.js';
@ -15,7 +18,9 @@ import {
set_active_effect, set_active_effect,
set_active_reaction, set_active_reaction,
reset_is_throwing_error, reset_is_throwing_error,
update_effect update_effect,
check_dirtiness,
set_signal_status
} from '../../runtime.js'; } from '../../runtime.js';
import { import {
hydrate_next, hydrate_next,
@ -45,6 +50,11 @@ var flags = EFFECT_TRANSPARENT | EFFECT_PRESERVED | BOUNDARY_EFFECT;
/** @type {Fork | null} */ /** @type {Fork | null} */
export var active_fork = null; export var active_fork = null;
/** @param {Fork | null} v */
export function set_active_fork(v) {
active_fork = v;
}
/** /**
* @param {TemplateNode} node * @param {TemplateNode} node
* @param {BoundaryProps} props * @param {BoundaryProps} props
@ -103,8 +113,6 @@ export class Boundary {
* @param {((anchor: Node) => void)} children * @param {((anchor: Node) => void)} children
*/ */
constructor(node, props, children) { constructor(node, props, children) {
window.boundary = this;
this.#anchor = node; this.#anchor = node;
this.#props = props; this.#props = props;
this.#children = children; this.#children = children;
@ -321,7 +329,7 @@ export class Boundary {
* @param {(fork: Fork) => void} fn * @param {(fork: Fork) => void} fn
*/ */
fork(fn) { fork(fn) {
if (!active_fork || !this.#forks.has(active_fork)) { if (active_fork === null || !this.#forks.has(active_fork)) {
active_fork = new Fork(this, changeset); active_fork = new Fork(this, changeset);
this.#forks.add(active_fork); this.#forks.add(active_fork);
} }
@ -329,7 +337,7 @@ export class Boundary {
fn(active_fork); fn(active_fork);
active_fork.commit(); active_fork.commit();
active_fork = null; // active_fork = null;
} }
/** /**
@ -379,11 +387,11 @@ export class Fork {
/** @type {Set<() => void>} */ /** @type {Set<() => void>} */
#callbacks = new Set(); #callbacks = new Set();
/** @type {Effect[]} */ /** @type {Set<Effect>} */
#render_effects = []; #render_effects = new Set();
/** @type {Effect[]} */ /** @type {Set<Effect>} */
#effects = []; #effects = new Set();
#pending_count = 0; #pending_count = 0;
@ -416,7 +424,7 @@ export class Fork {
/** @param {Effect} effect */ /** @param {Effect} effect */
add_effect(effect) { add_effect(effect) {
((effect.f & RENDER_EFFECT) !== 0 ? this.#render_effects : this.#effects).push(effect); ((effect.f & RENDER_EFFECT) !== 0 ? this.#render_effects : this.#effects).add(effect);
} }
commit() { commit() {
@ -426,9 +434,15 @@ export class Fork {
for (const e of this.#render_effects) { for (const e of this.#render_effects) {
try { try {
// if (check_dirtiness(e)) { set_signal_status(
update_effect(e); e,
// } (e.f & EFFECT_RAN) === 0 || e.deps?.some((d) => this.changeset.has(d))
? DIRTY
: MAYBE_DIRTY
);
if (check_dirtiness(e)) {
update_effect(e);
}
} catch (error) { } catch (error) {
handle_error(error, e, null, e.ctx); handle_error(error, e, null, e.ctx);
} }
@ -441,9 +455,15 @@ export class Fork {
for (const e of this.#effects) { for (const e of this.#effects) {
try { try {
// if (check_dirtiness(e)) { set_signal_status(
update_effect(e); e,
// } (e.f & EFFECT_RAN) === 0 || e.deps?.some((d) => this.changeset.has(d))
? DIRTY
: MAYBE_DIRTY
);
if (check_dirtiness(e)) {
update_effect(e);
}
} catch (error) { } catch (error) {
handle_error(error, e, null, e.ctx); handle_error(error, e, null, e.ctx);
} }

@ -373,7 +373,9 @@ export function template_effect(fn, sync = [], async = [], d = derived) {
* @param {Value[]} deriveds * @param {Value[]} deriveds
*/ */
function create_template_effect(fn, deriveds) { function create_template_effect(fn, deriveds) {
var effect = () => fn(...deriveds.map(get)); var effect = () => {
fn(...deriveds.map(get));
};
if (DEV) { if (DEV) {
define_property(effect, 'name', { define_property(effect, 'name', {

@ -48,7 +48,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 { active_fork, Boundary, Fork } from './dom/blocks/boundary.js'; import { active_fork, Boundary, Fork, set_active_fork } 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;
@ -706,6 +706,7 @@ function flush_queued_root_effects(root_effects) {
} finally { } finally {
is_flushing_effect = previously_flushing_effect; is_flushing_effect = previously_flushing_effect;
changeset.clear(); changeset.clear();
set_active_fork(null);
} }
} }
@ -822,7 +823,7 @@ function process_effects(effect, fork) {
if (!is_skippable_branch && (flags & INERT) === 0) { if (!is_skippable_branch && (flags & INERT) === 0) {
if (fork !== undefined && (flags & (BLOCK_EFFECT | BRANCH_EFFECT)) === 0) { if (fork !== undefined && (flags & (BLOCK_EFFECT | BRANCH_EFFECT)) === 0) {
if (check_dirtiness(current_effect)) { if ((current_effect.f & CLEAN) === 0) {
// Inside a boundary, defer everything except block/branch effects // Inside a boundary, defer everything except block/branch effects
fork.add_effect(current_effect); fork.add_effect(current_effect);

Loading…
Cancel
Save