svelte icon indicating copy to clipboard operation
svelte copied to clipboard

feat: provide guidance in browser console when logging `$state` objects

Open dummdidumm opened this issue 1 year ago • 2 comments

Wrap console.log/warn/error statements in DEV mode with a check whether or not they contain state objects. Closes #13123

This is an alternative or enhancement to #13070. Alternative if we deem it the better solution. Enhancement because it's not as robust as a custom formatter: We only check the top level of each entry (though we could maybe traverse a few levels), and if you're logging class instances, snapshot currently stops at the boundaries there and so you don't get snapshotted values for these (arguably this is a more general problem of $inspect and $state.snapshot), whereas with custom formatter it doesn't matter at which level you come across it.

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

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

dummdidumm avatar Sep 05 '24 15:09 dummdidumm

🦋 Changeset detected

Latest commit: ec9ea5d0f95c99d95fd6e26c5e35bbd9529a3584

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 Sep 05 '24 15:09 changeset-bot[bot]

I think we need this in addition to the formatter as for many people that use Chrome, the experience of using the formatter will exceed the experience of anything else. This can serve as a nice fallback for those on Safari.

trueadm avatar Sep 05 '24 16:09 trueadm

@dummdidumm I think this is missing something like an untrack. $effects now fire that otherwise would not. REPL

brunnerh avatar Sep 16 '24 22:09 brunnerh