{{ message }}
Repository navigation
Conversation
…isposed The initial subscription had no teardown outside a component, so an observer created inside $effect.root survived the disposer.
Contributor
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

🎯 Changes
Fixes #11587.
A query created inside
$effect.rootstays subscribed after the root's disposer runs. The observer is never released, so the cache entry survives itsgcTime, interval refetches keep firing, and a pending request that uses itsAbortSignalis never aborted.createBaseQuerysubscribes eagerly, outside any effect, so that the subscription exists on the server and on suspended branches. Two things are meant to tear that subscription down later:watchChangeseffect on[isRestoring.current, observer], which returns a cleanup, but only from its second run, since the helper skips the first invocationonDestroy, which throws outside a component and is swallowed by the surroundingtryInside
$effect.rootneither applies, so the first subscription has no teardown. This adds one effect whose only job is to unsubscribe on teardown, which the root disposer runs. In a component it is redundant withonDestroy, and unsubscribing twice is a no-op. It is in atryfor the same reason as theonDestroynext to it: outside an effect context the call throws, and that should not become an error for callers. During SSR the effect does not run andonDestroystill handles cleanup.Tests
packages/svelte-query/tests/createQuery/observer-cleanup.svelte.test.tsis the reproducer from the issue, written by @Osraka, included with their commit as the source. It coverscreateQueryandcreateInfiniteQueryin the success, error and disabled states, disposal before the first effect runs, signal abortion, interval refetches, and two controls that already passed: normal component unmount and disposal after switching clients.test:eslint,test:lib,test:types,test:buildandbuildpass for@tanstack/svelte-query, andtest:sherif,test:knipandtest:docspass for the repository. (pnpm run test:pritself hung with no output on my machine before running anything, so I ran its targets directly.)On #11542 and #11557: both branch from before #9810, so this reproducer passes there only because their base predates the regression. Neither merges onto current
mainwithout a conflict in this file, and both target different symptoms.✅ Checklist
pnpm run test:pr, or these tests do not apply to this pull request.🚀 Release Impact
Summary by CodeRabbit
Bug Fixes
Tests