diff --git a/.changeset/sharp-tigers-notice.md b/.changeset/sharp-tigers-notice.md new file mode 100644 index 0000000000..b519385066 --- /dev/null +++ b/.changeset/sharp-tigers-notice.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: @debug does not work with proxied-state diff --git a/packages/svelte/src/compiler/phases/3-transform/client/visitors/DebugTag.js b/packages/svelte/src/compiler/phases/3-transform/client/visitors/DebugTag.js index 685d305ba4..d2697fd039 100644 --- a/packages/svelte/src/compiler/phases/3-transform/client/visitors/DebugTag.js +++ b/packages/svelte/src/compiler/phases/3-transform/client/visitors/DebugTag.js @@ -9,9 +9,15 @@ import * as b from '../../../../utils/builders.js'; */ export function DebugTag(node, context) { const object = b.object( - node.identifiers.map((identifier) => - b.prop('init', identifier, /** @type {Expression} */ (context.visit(identifier))) - ) + node.identifiers.map((identifier) => { + const visited = b.call('$.snapshot', /** @type {Expression} */ (context.visit(identifier))); + + return b.prop( + 'init', + identifier, + context.state.analysis.runes ? visited : b.call('$.untrack', b.thunk(visited)) + ); + }) ); const call = b.call('console.log', object); diff --git a/packages/svelte/tests/runtime-runes/samples/debug-tag-object/_config.js b/packages/svelte/tests/runtime-runes/samples/debug-tag-object/_config.js new file mode 100644 index 0000000000..5d3440617b --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/debug-tag-object/_config.js @@ -0,0 +1,22 @@ +import { flushSync } from 'svelte'; +import { test } from '../../test'; + +export default test({ + compileOptions: { + dev: true + }, + + test({ assert, target, logs }) { + const b1 = target.querySelector('button'); + b1?.click(); + flushSync(); + b1?.click(); + flushSync(); + + assert.deepEqual(logs, [ + { count: { current: 0 } }, + { count: { current: 1 } }, + { count: { current: 2 } } + ]); + } +}); diff --git a/packages/svelte/tests/runtime-runes/samples/debug-tag-object/main.svelte b/packages/svelte/tests/runtime-runes/samples/debug-tag-object/main.svelte new file mode 100644 index 0000000000..ef332772ad --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/debug-tag-object/main.svelte @@ -0,0 +1,7 @@ + + +{@debug count} + +