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: use get in constructor for deriveds #15300

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

paoloricciuti
Copy link
Member

Closes #15288

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

Copy link

changeset-bot bot commented Feb 14, 2025

🦋 Changeset detected

Latest commit: 120aaa8

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

Copy link
Contributor

Playground

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

@paoloricciuti
Copy link
Member Author

Hello,

I think the $.get() should be wrapped by an untrack(), otherwise this can have fire unwanted effect if the class is created on an effect.

Example here where increment will rebuild a new Foo :

https://svelte.dev/playground/hello-world?version=pr-15300#H4sIAAAAAAAACnVSwW7CMAz9lSgg0Q4E047QVtpl2j-MHUrqsoiQVIkLm6r---KkdBViqtI4z-_Zjp2O6_IMfMvfQSnDrsaqiiVQSYQq5SteSwWObz86jj8N8Qjw-KB6bZq1u4BCwg6lg0e4MBpBow_DMyesbLDY6z3Kc2Msso61Gm0pTqxntTVntojCxY5ItIQqnWNvxrAuQBj_s0upWmA5mzssEZLndMAr0x5UcFRg5QWqBL-kWw_8J_aSUujA9aU5tK1AYxMqPR1TYNAQ5gPRtrs5SGMUrJU5Bs2KTcLfDrGGdBD1t3xSCwtn34zkPlOUL5f3iiMgC66pwgK2Vk_zPpLFGv7VRfdEOKi9oYDmMlx-zyuoy1bhnvsR-a421jQuiXcjZu0nM04hwnOoaxCYMJ89L24FRKKGKw0z9juwe9qyzd_b8F92aBGNZkYLJcUp75I0L3yA9aSFfTEesk3ke3U3kzXVFK6UVfJSUKa8IzFZfbYhcPSG_kV3MO_9sU-REO2R0W1kHZrmXznCN_Ktf0zQf_a_2CIFlFcDAAA=

Mh ..I wonder if it should actually be the opposite and we should also track reads to state inside the constructor...effectively you are reading state, why should we assume that you don't want that to be reactive (you can always untrack yourself but if we untrack for you you would have no way of preventing it) 🤔

@adiguba
Copy link
Contributor

adiguba commented Feb 15, 2025

I'm not sure about that, but personally I think that constructor should not be reactive on their own value...

I think that's the reason for using .v instead of $.get()

@paoloricciuti
Copy link
Member Author

I'm not sure about that, but personally I think that constructor should not be reactive on their own value...

I think that's the reason for using .v instead of $.get()

I think it was made as an optimization but let me explore this a bit more

@paoloricciuti
Copy link
Member Author

I'd argue - the behavior shouldn't differ from the classless variant. Otherwise it will confuse people.

I mean classes are already a bit different but I think I agree with this in this case: and I lean more towards this case because, again, if you want to untrack this by yourself you can, if we untrack for you you can't track it

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.

Derived private property calculated after constructor
3 participants