Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: @debug does not work with proxied-state #13690

Merged
merged 4 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/sharp-tigers-notice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: @debug does not work with proxied-state
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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 } }
]);
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script>
let count = $state({ current: 0 });
</script>

{@debug count}

<button onclick={()=> count.current++}>+</button>