Skip to content

docs: tweak untrack description, provide an example of usage #14085

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

Merged
merged 3 commits into from
Nov 1, 2024

Conversation

Rich-Harris
Copy link
Member

alternative to #14060. In general we should put documentation on the functions themselves — that way there's a single source that populates everything.

It's also good to use realistic motivating examples where possible — in particular it's good to avoid console.log in examples of effects, since it's better to use $inspect (particularly when dealing with state proxies).

Copy link

changeset-bot bot commented Oct 31, 2024

⚠️ No Changeset found

Latest commit: f6f0c26

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

Copy link

pkg-pr-new bot commented Oct 31, 2024

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

commit: f6f0c26

@Conduitry
Copy link
Member

Do we also want to mention that any state written to inside an untrack() will not trigger $effect()s/$derived()s to re-run?

@Rich-Harris
Copy link
Member Author

No, because it's not true

@Conduitry
Copy link
Member

Well that's a good reason to not do it. I recall that it has some sort of an effect in this area. There was some issue recently where someone really wanted to run mutations inside the template and I suggested using untrack because it seemed to work in that case. Maybe it was just blocking the read portion of an a += 1, though.

@Rich-Harris
Copy link
Member Author

Yep, if you do thing += 1 inside an untrack then it won't infinite loop because you're not reading thing before you update it

@@ -2,7 +2,7 @@
title: $effect
---

Effects are what make your application _do things_. When Svelte runs an effect function, it tracks which pieces of state (and derived state) are accessed, and re-runs the function when that state later changes.
Effects are what make your application _do things_. When Svelte runs an effect function, it tracks which pieces of state (and derived state) are accessed (unless accessed inside [`untrack`](svelte#untrack)), and re-runs the function when that state later changes.
Copy link

@gterras gterras Nov 1, 2024

Choose a reason for hiding this comment

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

Effects are what make your application do things This sounds too broad, you can actually make applications do things without using effect. I suppose react is out of question, why not something like $effect lets you take full control on your application?

Copy link
Member Author

Choose a reason for hiding this comment

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

you can actually make applications do things without using effect

Like what?

Copy link

Choose a reason for hiding this comment

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

Like anything that don't use effect... like 90% of the example of the docs and tutorials? Is this a real question?

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you mean like the {name} in <h1>hello {name}</h1>? Because that is an effect. This is made quite clear in the following sentence

Copy link

@gterras gterras Nov 1, 2024

Choose a reason for hiding this comment

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

Documenting the implementation is pointless in a user docs. This makes the sentence even more confusing. This reads:

"Effects is everywhere, you and Svelte cannot do anything without effects. Avoid overusing effects!

This screams read the full page or you will miss out to the uninitiated. Also this is a direct contradiction with the when not to use effect section which heavily tempers this statement.

@dummdidumm dummdidumm merged commit 6a2c28c into main Nov 1, 2024
10 checks passed
@dummdidumm dummdidumm deleted the untrack-docs branch November 1, 2024 07:49
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.

4 participants