fix: prevent reactivity loss during/after fork#17335
fix: prevent reactivity loss during/after fork#17335hmnd wants to merge 31 commits intosveltejs:mainfrom
Conversation
fixes sveltejs#17197, fixes sveltejs#17304, fixes sveltejs#17301, fixes sveltejs#17309
🦋 Changeset detectedLatest commit: 1f7975c 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.
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.
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. |
|
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 |
|
Thank you! Another incredibly helpful investigation. It turns out the reactivity loss isn't fork-specific — you can get the same result without it. Essentially what's happening is that because |
|
Merged #17581 so will close this |
|
Aha nice find! Sorry I wasn't quite on the right track, but glad to have helped and happy to see this fixed :) |
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