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

Conversation

adiguba
Copy link
Contributor

@adiguba adiguba commented Oct 19, 2024

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

  • 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
  • Prefix your PR title with feat:, fix:, chore:, or docs:.
  • 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

  • Run the tests with pnpm test and lint the project with pnpm lint

Copy link

changeset-bot bot commented Oct 19, 2024

🦋 Changeset detected

Latest commit: e4ee0f6

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

@trueadm
Copy link
Contributor

trueadm commented Oct 19, 2024

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

@adiguba
Copy link
Contributor Author

adiguba commented Oct 19, 2024

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.

@trueadm
Copy link
Contributor

trueadm commented Oct 19, 2024

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.

@adiguba
Copy link
Contributor Author

adiguba commented Oct 19, 2024

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.

@trueadm
Copy link
Contributor

trueadm commented Oct 21, 2024

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 trueadm merged commit ad578a5 into sveltejs:main Oct 21, 2024
9 checks passed
@github-actions github-actions bot mentioned this pull request Oct 21, 2024
@adiguba adiguba deleted the fix-13687 branch October 24, 2024 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

{@debug object} doesn't fire when object.property changes
2 participants