fix: freeze effects-inside-deriveds when disconnecting, unfreeze on reconnect#17682
Conversation
🦋 Changeset detectedLatest commit: bfa7cc4 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 |
|
…nside a derived that doesn't probably create more work than it saves
dummdidumm
left a comment
There was a problem hiding this comment.
This works and is a good solution, but it adds more code and I'm wondering if we should instead opt for an overall "simpler" model. I believe the main reason people run into connect/disconnect is because they create global state outside of a reactive context. So what if we allow to create deriveds/effects outside of a reactive context, and if so we warn about it and just never clean it up? This likely makes the whole connect/disconnect much simpler, and we can instead rerun deriveds when they reconnect - which is much rarer in this world.
Anyway that's all food for thought and shouldn't hold up this PR, because the current behavior definitely is more broken.
|
Ownership (whether or not a derived was created inside an effect tree) and connection (whether or not anything currently depends on the derived) aren't the same thing though. Anyway, I just realised we don't handle abort signals in this PR, and in the process of fixing that realised that we're currently over-running effects for some reason... investigating |
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. # Releases ## [email protected] ### Patch Changes - fix: take into account `nodeName` case sensitivity on XHTML pages ([#17689](#17689)) - fix: render `multiple` and `selected` attributes as empty strings for XHTML compliance ([#17689](#17689)) - fix: always lowercase HTML elements, for XHTML compliance ([#17664](#17664)) - fix: freeze effects-inside-deriveds when disconnecting, unfreeze on reconnect ([#17682](#17682)) - fix: propagate `$effect` errors to `<svelte:boundary>` ([#17684](#17684)) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This supersedes #16595, and fixes the issue by 'freezing' effects inside deriveds when those deriveds are disconnected, and unfreezing them when they reconnect. This is preferable to the current asymmetric behaviour on
main(in which effects are destroyed when the derived is disconnected, and never recreated) and #16595, which causes the derived itself to be re-evaluated.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