-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
fix: prevent reactivity loss during/after fork #17335
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
base: main
Are you sure you want to change the base?
Conversation
fixes sveltejs#17197, fixes sveltejs#17304, fixes sveltejs#17301, fixes sveltejs#17309
🦋 Changeset detectedLatest commit: 098dc55 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
|
|
I tested this with my repro mentioned in this comment - sveltejs/kit#15059 (comment) |
| // Track branches toggled during fork execution so we can restore | ||
| // their CLEAN flag after flush | ||
| if (current_batch !== null && current_batch.is_fork) { | ||
| (current_batch.toggled_branches ??= new Set()).add(effect); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it makes sense...there's only one thing that it kinda irks me here: we are restoring ALL the branches to CLEAN but wouldn't this lead to over-running?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm I don't think that's a concern because we only do this for branches that had CLEAN before the fork. I'm pretty sure setting CLEAN doesn't necessarily mean branches will run either, it just allows them to be scheduled.
|
I am not sure If I understand This seems to be even execution order-dependent. |
|
Thanks David. I think it's completely fine to keep the PRs separate as they make reviewing the changes easier. I'd recommend editing the descriptions to mention how the two are linked. Unfortunately, I'm not too familiar with the Svelte codebase so I'd wait for one of the more experienced maintainers to review the two PRs once everyone's back from their holidays. |
Let's try pulling in sveltejs/svelte#17335.
|
Thank you for tackling this! While it seems to solve the problem, I'm not sure if there's a bigger fix needed. Take this example: derived graph changes, no longer reactive outside fork I'm not sure yet if a separate fix for this problem is "enough" or if this hints at the possibility of a more general fix that solves both the bug this PR fixes and the one in the derived example. |
|
Great catch! I've fixed it simply by not removing reactions during forks. This does mean we potentially keep stale deps around for a bit longer, buth they'll still get cleaned up after the fork. |
2817b9d to
aa647c7
Compare
|
Fixed a slight bug in my fix to @dummdidumm's repro. There was previously an attempt to ensure deriveds get their value set if first initalizied in a fork, but this was not working properly because This hadn't shown itself yet because |
fixes #17197, fixes #17304, fixes #17301, fixes #17309, possibly others
Thanks to @dummdidumm's prior digging into this here
Before submitting the PR, please make sure you do the following
feat:,fix:,chore:, ordocs:.packages/svelte/src, add a changeset (npx changeset).Tests and linting
pnpm testand lint the project withpnpm lint