for unowned deriveds, throw errors lazily

pull/15844/head
Rich Harris 3 months ago
parent fdd009b60d
commit 5c0a4a02a5

@ -1,17 +1,23 @@
/** @import { Effect } from '#client' */ /** @import { Derived, Effect } from '#client' */
/** @import { Boundary } from './dom/blocks/boundary.js' */ /** @import { Boundary } from './dom/blocks/boundary.js' */
import { DEV } from 'esm-env'; import { DEV } from 'esm-env';
import { FILENAME } from '../../constants.js'; import { FILENAME } from '../../constants.js';
import { is_firefox } from './dom/operations.js'; import { is_firefox } from './dom/operations.js';
import { BOUNDARY_EFFECT, EFFECT_RAN } from './constants.js'; import { ASYNC_ERROR, BOUNDARY_EFFECT, EFFECT_RAN } from './constants.js';
import { define_property, get_descriptor } from '../shared/utils.js'; import { define_property, get_descriptor } from '../shared/utils.js';
import { active_effect } from './runtime.js'; import { active_effect, active_reaction } from './runtime.js';
/** /**
* @param {unknown} error * @param {unknown} error
*/ */
export function handle_error(error) { export function handle_error(error) {
var effect = /** @type {Effect} */ (active_effect); var effect = active_effect;
// for unowned deriveds, don't throw until we read the value
if (effect === null) {
/** @type {Derived} */ (active_reaction).f |= ASYNC_ERROR;
return error;
}
if (DEV && error instanceof Error) { if (DEV && error instanceof Error) {
// adjust_error(error, effect); // adjust_error(error, effect);

@ -369,9 +369,13 @@ export function update_reaction(reaction) {
} }
} }
if ((reaction.f & ASYNC_ERROR) !== 0) {
reaction.f ^= ASYNC_ERROR;
}
return result; return result;
} catch (error) { } catch (error) {
handle_error(error); return handle_error(error);
} finally { } finally {
reaction.f ^= REACTION_IS_UPDATING; reaction.f ^= REACTION_IS_UPDATING;
new_deps = previous_deps; new_deps = previous_deps;

Loading…
Cancel
Save