diff --git a/.changeset/violet-mugs-behave.md b/.changeset/violet-mugs-behave.md new file mode 100644 index 0000000000..c09d0ba583 --- /dev/null +++ b/.changeset/violet-mugs-behave.md @@ -0,0 +1,5 @@ +--- +"svelte": patch +--- + +fix: ensure $inspect untracks inspected object diff --git a/packages/svelte/src/internal/client/dev/inspect.js b/packages/svelte/src/internal/client/dev/inspect.js index 342cdbb2e5..8b6b6e45a6 100644 --- a/packages/svelte/src/internal/client/dev/inspect.js +++ b/packages/svelte/src/internal/client/dev/inspect.js @@ -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); }; diff --git a/packages/svelte/tests/runtime-runes/samples/inspect-deep/_config.js b/packages/svelte/tests/runtime-runes/samples/inspect-deep/_config.js new file mode 100644 index 0000000000..f7480b0e7b --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/inspect-deep/_config.js @@ -0,0 +1,11 @@ +import { test } from '../../test'; + +export default test({ + compileOptions: { + dev: true + }, + + async test({ assert, logs }) { + assert.deepEqual(logs, ['init', undefined, 'update', [{}]]); + } +}); diff --git a/packages/svelte/tests/runtime-runes/samples/inspect-deep/main.svelte b/packages/svelte/tests/runtime-runes/samples/inspect-deep/main.svelte new file mode 100644 index 0000000000..0b6b196b13 --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/inspect-deep/main.svelte @@ -0,0 +1,11 @@ + +