Skip to content

Conversation

@Rich-Harris
Copy link
Member

Am looking at simplifying all the UNOWNED/DISCONNECTED logic. I have a sneaking suspicion that it's all much more complicated than it needs to be.

One piece of low-hanging fruit: we don't need to check the UNOWNED flag when throwing the e.effect_in_unowned_derived error — since we set active_effect to be the parent effect of a derived whenever we execute it, if active_effect is null then we already know it's an unowned derived.

@changeset-bot
Copy link

changeset-bot bot commented Nov 3, 2025

⚠️ No Changeset found

Latest commit: 64f078d

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

@github-actions
Copy link
Contributor

github-actions bot commented Nov 3, 2025

Playground

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

Copy link
Member

@dummdidumm dummdidumm left a comment

Choose a reason for hiding this comment

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

I'm not quite sure we can do this - the UNOWNED status is dynamic and not solely dependent on the parent chain of the derived. i.e. a derived can have a parent that is an effect but still be UNOWNED because it was read outside that effect in the meantime

@Rich-Harris
Copy link
Member Author

That's all the more reason to change it! idea is to prevent the use of $effect inside a $derived that is itself created outside of an $effect. That's reflected in the active_effect === null check, but — given that we use UNOWNED to mean something other than 'is unowned' — might not be reflected in the current logic

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.

3 participants