Skip to content

Commit

Permalink
fix: ensure $inspect untracks inspected object (#11432)
Browse files Browse the repository at this point in the history
  • Loading branch information
trueadm committed May 2, 2024
1 parent fcdad4c commit 1f9ad03
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/violet-mugs-behave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte": patch
---

fix: ensure $inspect untracks inspected object
4 changes: 2 additions & 2 deletions packages/svelte/src/internal/client/dev/inspect.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { snapshot } from '../proxy.js';
import { render_effect, validate_effect } from '../reactivity/effects.js';
import { current_effect, deep_read } from '../runtime.js';
import { current_effect, deep_read, untrack } from '../runtime.js';
import { array_prototype, get_prototype_of, object_prototype } from '../utils.js';

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { test } from '../../test';

export default test({
compileOptions: {
dev: true
},

async test({ assert, logs }) {
assert.deepEqual(logs, ['init', undefined, 'update', [{}]]);
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<script>
let items = [{}];
let data = $state();
$effect(() => {
data = items.slice(0, 1);
});
$inspect(data);
</script>

0 comments on commit 1f9ad03

Please sign in to comment.