Skip to content

Commit 1f9ad03

Browse files
authored
fix: ensure $inspect untracks inspected object (#11432)
1 parent fcdad4c commit 1f9ad03

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

.changeset/violet-mugs-behave.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+
fix: ensure $inspect untracks inspected object

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { snapshot } from '../proxy.js';
22
import { render_effect, validate_effect } from '../reactivity/effects.js';
3-
import { current_effect, deep_read } from '../runtime.js';
3+
import { current_effect, deep_read, untrack } from '../runtime.js';
44
import { array_prototype, get_prototype_of, object_prototype } from '../utils.js';
55

66
/** @type {Function | null} */
@@ -28,7 +28,7 @@ export function inspect(get_value, inspector = console.log) {
2828
// calling `inspector` directly inside the effect, so that
2929
// we get useful stack traces
3030
var fn = () => {
31-
const value = deep_snapshot(get_value());
31+
const value = untrack(() => deep_snapshot(get_value()));
3232
inspector(initial ? 'init' : 'update', ...value);
3333
};
3434

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
compileOptions: {
5+
dev: true
6+
},
7+
8+
async test({ assert, logs }) {
9+
assert.deepEqual(logs, ['init', undefined, 'update', [{}]]);
10+
}
11+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<script>
2+
let items = [{}];
3+
let data = $state();
4+
5+
$effect(() => {
6+
data = items.slice(0, 1);
7+
});
8+
9+
$inspect(data);
10+
</script>
11+

0 commit comments

Comments
 (0)