Skip to content

Commit 5c0a4a0

Browse files
committed
for unowned deriveds, throw errors lazily
1 parent fdd009b commit 5c0a4a0

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

packages/svelte/src/internal/client/error-handling.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
1-
/** @import { Effect } from '#client' */
1+
/** @import { Derived, Effect } from '#client' */
22
/** @import { Boundary } from './dom/blocks/boundary.js' */
33
import { DEV } from 'esm-env';
44
import { FILENAME } from '../../constants.js';
55
import { is_firefox } from './dom/operations.js';
6-
import { BOUNDARY_EFFECT, EFFECT_RAN } from './constants.js';
6+
import { ASYNC_ERROR, BOUNDARY_EFFECT, EFFECT_RAN } from './constants.js';
77
import { define_property, get_descriptor } from '../shared/utils.js';
8-
import { active_effect } from './runtime.js';
8+
import { active_effect, active_reaction } from './runtime.js';
99

1010
/**
1111
* @param {unknown} error
1212
*/
1313
export function handle_error(error) {
14-
var effect = /** @type {Effect} */ (active_effect);
14+
var effect = active_effect;
15+
16+
// for unowned deriveds, don't throw until we read the value
17+
if (effect === null) {
18+
/** @type {Derived} */ (active_reaction).f |= ASYNC_ERROR;
19+
return error;
20+
}
1521

1622
if (DEV && error instanceof Error) {
1723
// adjust_error(error, effect);

packages/svelte/src/internal/client/runtime.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,9 +369,13 @@ export function update_reaction(reaction) {
369369
}
370370
}
371371

372+
if ((reaction.f & ASYNC_ERROR) !== 0) {
373+
reaction.f ^= ASYNC_ERROR;
374+
}
375+
372376
return result;
373377
} catch (error) {
374-
handle_error(error);
378+
return handle_error(error);
375379
} finally {
376380
reaction.f ^= REACTION_IS_UPDATING;
377381
new_deps = previous_deps;

0 commit comments

Comments
 (0)