svelte icon indicating copy to clipboard operation
svelte copied to clipboard

fix: @debug does not work with proxied-state

Open adiguba opened this issue 1 year ago • 5 comments

Fix #13687

The console.log() generated by @debug receive the proxied state, which causes two bugs :

  • It displays the proxy instead of the object himself.
  • And so this breaks reactivity as object is not read.

This simple fix simply call $.snapshot() on all the values of {@debug} in order to print correctly the proxied states.

This adds an unnecessary call when the variable is not a proxy-state, but I don't think this is problematic for a debugging tool.

Note : I don't know if this requires a test (and I wouldn't know how to write it)

Svelte 5 rewrite

Please note that the Svelte codebase is currently being rewritten for Svelte 5. Changes should target Svelte 5, which lives on the default branch (main).

If your PR concerns Svelte 4 (including updates to svelte.dev.docs), please ensure the base branch is svelte-4 and not main.

Before submitting the PR, please make sure you do the following

  • [X] It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • [X] Prefix your PR title with feat:, fix:, chore:, or docs:.
  • [X] This message body should clearly illustrate what problems it solves.
  • [ ] Ideally, include a test that fails without this PR but passes with it.

Tests and linting

  • [X] Run the tests with pnpm test and lint the project with pnpm lint

adiguba avatar Oct 19 '24 08:10 adiguba

🦋 Changeset detected

Latest commit: e4ee0f6769824f3e60b74bc03b4fa66ba9aef8f4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

changeset-bot[bot] avatar Oct 19 '24 08:10 changeset-bot[bot]

I think we also want to untrack it otherwise it will fire for every change within, which is now how debug tags work.

trueadm avatar Oct 19 '24 11:10 trueadm

I think we also want to untrack it otherwise it will fire for every change within, which is now how debug tags work.

I'm not used to @debug, but the docs say that it's fire on every change :

https://svelte.dev/docs/special-tags#debug The {@debug ...} tag offers an alternative to console.log(...). It logs the values of specific variables whenever they change, and pauses code execution if you have devtools open.

adiguba avatar Oct 19 '24 11:10 adiguba

I'm not used to @debug, but the docs say that it's fire on every change :

Not for deep state though, @debug isn't designed to do that, $inspect is meant to do that.

trueadm avatar Oct 19 '24 12:10 trueadm

On Svelte 4 or in non-runes mode, @debug work for deep state :

Example : https://svelte-5-preview.vercel.app/#H4sIAAAAAAAAClWO3QrCMAyFXyXkSlH8ua3r0OdwXrguk-JsS5sKUvrurhtDvErOSb6TJOz1QAHFNaG5vwgFXpzDLfLHFRHeNDCNOtjoVXGqoLx2XDem4YEYlI2GyYOENPcCDpBPjan2v01TtZHZGrBGDVo9ZVqtQdYLvJsqbCQc8xSczh218bHMc_EmMAhIf1Auh-bwGsY_X7bTvaYOBftI-Za_OtkbkuIAAAA=

I never used @debug and $inspect() seem a better solution for me. But as long as @debug is not removed I think it should be responsive to any changes.

adiguba avatar Oct 19 '24 21:10 adiguba

What I mean is that we probably want to untrack in legacy mode, and in runes mode we don't need the untrack. Otherwise this might cause unexpected things happening in legacy components.

I updated the PR and added a test :)

trueadm avatar Oct 21 '24 15:10 trueadm