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: avoid stack overflows from derived recursion #12739

Closed
wants to merge 2 commits into from

Conversation

trueadm
Copy link
Contributor

@trueadm trueadm commented Aug 5, 2024

Fixes #12723. We can actually track updating deriveds and prevent stack overflows internally.

Copy link

changeset-bot bot commented Aug 5, 2024

🦋 Changeset detected

Latest commit: 7a38454

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

@Rich-Harris
Copy link
Member

Do we definitely want to do this? We're adding work to a hot code path and creating a bit of an ambiguous situation in the case where the derivation refers to itself on the first run, both in runtime terms (the value is null initially which is weird enough — it should be undefined — and likely to cause problems when accessing properties of the derived value later on) and in terms of types:

image

It's solvable with effects, without penalising the vast majority of people who don't need this. I'd be in favour of a dev time check that printed a more helpful error — something like this instead of 'too much recursion':

A derived value cannot refer to itself

@trueadm
Copy link
Contributor Author

trueadm commented Aug 5, 2024

I'll add a compiler warning tomorrow :)

@trueadm trueadm closed this Aug 5, 2024
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.

untrack not working as expected in derived.by
2 participants