async-changeset
Rich Harris 7 months ago
parent 63be623021
commit 30cd46de11

@ -47,6 +47,7 @@ import { loop } from '../../loop.js';
export class Boundary { export class Boundary {
suspended = false; suspended = false;
inert = false;
/** @type {Boundary | null} */ /** @type {Boundary | null} */
parent; parent;
@ -106,13 +107,7 @@ export class Boundary {
this.parent = /** @type {Effect} */ (active_effect).b; this.parent = /** @type {Effect} */ (active_effect).b;
this.#effect = block(() => { this.#effect = block(() => {
var boundary_effect = /** @type {Effect} */ (active_effect); /** @type {Effect} */ (active_effect).b = this;
boundary_effect.b = this;
// @ts-ignore We re-use the effect's fn property to avoid allocation of an additional field
boundary_effect.fn = (/** @type {unknown} */ input) => {
this.error(input);
};
if (hydrating) { if (hydrating) {
hydrate_next(); hydrate_next();

@ -252,22 +252,19 @@ export function check_dirtiness(reaction) {
* @param {Effect} effect * @param {Effect} effect
*/ */
function propagate_error(error, effect) { function propagate_error(error, effect) {
/** @type {Effect | null} */ var boundary = effect.b;
var current = effect;
while (current !== null) { while (boundary !== null) {
if ((current.f & BOUNDARY_EFFECT) !== 0) { if (!boundary.inert) {
try { try {
// @ts-expect-error boundary.error(error);
current.fn(error);
return; return;
} catch { } catch {
// Remove boundary flag from effect boundary.inert = true;
current.f ^= BOUNDARY_EFFECT;
} }
} }
current = current.parent; boundary = boundary.parent;
} }
is_throwing_error = false; is_throwing_error = false;
@ -278,10 +275,7 @@ function propagate_error(error, effect) {
* @param {Effect} effect * @param {Effect} effect
*/ */
function should_rethrow_error(effect) { function should_rethrow_error(effect) {
return ( return (effect.f & DESTROYED) === 0 && (effect.parent === null || !effect.b || effect.b.inert);
(effect.f & DESTROYED) === 0 &&
(effect.parent === null || (effect.parent.f & BOUNDARY_EFFECT) === 0)
);
} }
export function reset_is_throwing_error() { export function reset_is_throwing_error() {

Loading…
Cancel
Save