Skip to content

Commit 5eccaf1

Browse files
committed
chore: avoid reporting inspections when an exception occurs
1 parent 6534f50 commit 5eccaf1

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

.changeset/light-crews-deny.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
chore: avoid reporting inspections when an exception occurs

packages/svelte/src/internal/client/dev/inspect.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { UNINITIALIZED } from '../../../constants.js';
12
import { snapshot } from '../../shared/clone.js';
23
import { inspect_effect, validate_effect } from '../reactivity/effects.js';
34

@@ -12,7 +13,22 @@ export function inspect(get_value, inspector = console.log) {
1213
let initial = true;
1314

1415
inspect_effect(() => {
15-
inspector(initial ? 'init' : 'update', ...snapshot(get_value(), true));
16+
/** @type {any} */
17+
var value = UNINITIALIZED;
18+
19+
// Capturing the value might result in an exception due to the inspect effect being
20+
// sync and thus operating on stale data. In the case we encounter an exception we
21+
// can bail-out of reporting the value
22+
try {
23+
value = get_value();
24+
} catch {
25+
// NO-OP
26+
}
27+
28+
if (value !== UNINITIALIZED) {
29+
inspector(initial ? 'init' : 'update', ...snapshot(value, true));
30+
}
31+
1632
initial = false;
1733
});
1834
}

0 commit comments

Comments
 (0)