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

feat: add $inspect.trace rune #14290

Merged
merged 59 commits into from
Dec 15, 2024
Merged

feat: add $inspect.trace rune #14290

merged 59 commits into from
Dec 15, 2024

Conversation

trueadm
Copy link
Contributor

@trueadm trueadm commented Nov 13, 2024

Closes #14265. This adds the $inspect.trace rune to Svelte which logs the reactive graph of the current reactive context. It must be placed in a block statement and requires a string passed as an argument which is the trace name.

Copy link

changeset-bot bot commented Nov 13, 2024

🦋 Changeset detected

Latest commit: ae3d8a1

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

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

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

Copy link
Contributor

Playground

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

WIP

WIP

WIP

WIP

WIP

WIP

WIP

WIP

WIP

WIP

WIP

WIP

WIP

WIP

WIP

WIP

WIP

WIP

WIP

WIP
@Rich-Harris
Copy link
Member

preview: https://svelte-dev-git-preview-svelte-14290-svelte.vercel.app/

this is an automated message

@trueadm trueadm marked this pull request as draft November 14, 2024 20:12
@trueadm trueadm changed the title WIP: add dev time tracing feat: add dev time reactive graph tracing Nov 14, 2024
@trueadm
Copy link
Contributor Author

trueadm commented Dec 14, 2024

So I think the placement rule should be that $inspect.trace must be in a function block

I agree, I've changed it so it has to be in a function. I didn't want to limit it to be the first entry as that can cause issues inside class constructors etc.

If we do that, I'd love it if we can get rid of the label argument, or at least make it optional — we can just use the function name, or $effect if it's the anonymous callback passed to $effect, and provide the location of the function. In rare cases there'll be no name that the compiler can determine, but the location should be sufficient. This feels way nicer than having to provide a label for something I'm probably only adding temporarily for debugging purposes.

It literally used to do exactly this, but I found it was just not useful at all. You mostly put it in effects, so it would just log $effect as the name each time and it didn't really help any finding it. I find an explicit name is far clearer, even if it's a bit less nicer than having it automagically work. Maybe the location is enough? If I can time tonight I can take a stab at it unless you do it before.

Also: why is this showing no reactive dependencies inside the effect?

Odd, it works for me locally, but not on the REPL?!

@Rich-Harris
Copy link
Member

issues inside class constructors etc

Can you elaborate? It should be fine as long as you're not using this in the label, no?

@trueadm
Copy link
Contributor Author

trueadm commented Dec 14, 2024

issues inside class constructors etc

Can you elaborate? It should be fine as long as you're not using this in the label, no?

They can't even use this in the label on reflection, it has to be a literal only, so ignore me!

@Rich-Harris Rich-Harris marked this pull request as ready for review December 15, 2024 14:19
@Rich-Harris Rich-Harris merged commit 5483495 into main Dec 15, 2024
11 checks passed
@Rich-Harris Rich-Harris deleted the trace-rune branch December 15, 2024 14:21
@github-actions github-actions bot mentioned this pull request Dec 15, 2024
Copy link

@hughes123b hughes123b left a comment

Choose a reason for hiding this comment

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

I thought I was hacked..

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 symbols for dependencies of user effects/deriveds
4 participants