fix: ensure $inspect untracks inspected object (#11432)

pull/11434/head
Dominic Gannaway 8 months ago committed by GitHub
parent fcdad4c166
commit 1f9ad03287
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
"svelte": patch
---
fix: ensure $inspect untracks inspected object

@ -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} */
@ -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);
};

@ -0,0 +1,11 @@
import { test } from '../../test';
export default test({
compileOptions: {
dev: true
},
async test({ assert, logs }) {
assert.deepEqual(logs, ['init', undefined, 'update', [{}]]);
}
});

@ -0,0 +1,11 @@
<script>
let items = [{}];
let data = $state();
$effect(() => {
data = items.slice(0, 1);
});
$inspect(data);
</script>
Loading…
Cancel
Save