Skip to content

Conversation

@Rich-Harris
Copy link
Member

Closes #16998. This is the least invasive version of the solution — by (effectively) doing this...

-$inspect(stuff)
+$inspect(stuff).with((...args) => console.log(...args));
-$inspect(stuff).with(console.trace);
+$inspect(stuff).with((...args) => console.trace(...args));

...we make the log come from the $inspect(...) callsite rather than the module containing the inspect helper — instead of this...

image

...we get this:

image

We could go further. If we updated the inspect function thusly...

untrack(() => {
-  inspector(initial ? 'init' : 'update', ...snap);
+ inspector(...snap);
+ if (!initial) console.log(get_stack('UpdatedAt'));
});

...then we would get this result:

image

(The label has to end with the string Error or it doesn't get formatted/sourcemapped correctly, hence UpdatedAtError.)

You could certainly make a case for that being the default. I also wonder if we should get rid of the init tag during SSR, or replace it with $inspect or something.

Thoughts?

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.
  • If this PR changes code within packages/svelte/src, add a changeset (npx changeset).

Tests and linting

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

@changeset-bot
Copy link

changeset-bot bot commented Oct 21, 2025

🦋 Changeset detected

Latest commit: e6242e6

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

@github-actions
Copy link
Contributor

Playground

pnpm add https://pkg.pr.new/svelte@17001

Copy link
Member

@paoloricciuti paoloricciuti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of maybe silly comments but this looks very noice.

@pngwn
Copy link
Member

pngwn commented Oct 21, 2025

I like it very much!!

I can already sense my frustrations melting away.

@pngwn
Copy link
Member

pngwn commented Oct 21, 2025

I also like the update at error thing. That would be very useful imo! Although people might complain and want a way to 'quieten' it.

@Rich-Harris
Copy link
Member Author

Perhaps the stack trace thing is the default but if you use with(...) you don't get that?

@pngwn
Copy link
Member

pngwn commented Oct 21, 2025

Yeah, I think that makes sense and is a nice switch to give users control.

@svelte-docs-bot
Copy link

@dummdidumm dummdidumm merged commit 4b32d6d into main Oct 22, 2025
18 checks passed
@dummdidumm dummdidumm deleted the gh-16998 branch October 22, 2025 10:04
@github-actions github-actions bot mentioned this pull request Oct 22, 2025
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.

Make console.log great again: better $inspect ergonomics

4 participants