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: set deriveds as CLEAN if they are assigned to #15592

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

paoloricciuti
Copy link
Member

Closes #15590

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 Mar 22, 2025

🦋 Changeset detected

Latest commit: 4e281a5

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

@svelte-docs-bot
Copy link

Copy link
Contributor

Playground

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

@trueadm
Copy link
Contributor

trueadm commented Mar 23, 2025

If the derived is unowned then it might not be safe to mark it as clean, but rather maybe dirty.

@paoloricciuti
Copy link
Member Author

If the derived is unowned then it might not be safe to mark it as clean, but rather maybe dirty.

Gotcha, will see if it works in a bit...can you help me come up with a test that actually test the problematic situation (the test I wrote is using unowned deriveds no?)

@paoloricciuti
Copy link
Member Author

Oh wait this has a bug

@paoloricciuti
Copy link
Member Author

Mmm this is more complex than i thought: if we reassign before the first read then the derived is not a reaction of the state and it will not be updated when the state changes 🤔

@paoloricciuti
Copy link
Member Author

@trueadm this fixes the bug i was talking about but it introduce a new constant and basically execute the derived without assigning the value and the status in the case where the derived is clean because it was assigned to (basically it's just to still register the dependency).

I couldn't come up with a better idea but i wonder if there's one.

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 isn't mutated when reassigned synchronously after definition
2 participants