-
Notifications
You must be signed in to change notification settings - Fork 249
docs: clarify query cancellation semantics #1694
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
Oops, something went wrong.
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.
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.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: TanStack/db
Length of output: 39251
🌐 Web query:
TanStack Query 5 observer lifecycle gcTime when query becomes inactive documentation💡 Result:
In TanStack Query v5, a query becomes inactive when it no longer has any active observers (e.g., all components using a hook like useQuery have unmounted) [1][2][3]. Once a query transitions to the inactive state, TanStack Query begins a garbage collection countdown based on the query's gcTime configuration [2][3]. Key aspects of this lifecycle include: 1. Inactive State: A query is considered inactive when it is present in the cache but is not currently being used by any observers [1][3]. Data persists in the cache in this state, allowing for instant reuse if the query becomes active again before the garbage collection timeout expires [2][3]. 2. gcTime (Garbage Collection Time): Formerly known as cacheTime in earlier versions, gcTime defines the duration (in milliseconds) that inactive query data remains in memory before being garbage collected and deleted [4][5][6]. 3. Default Behavior: The default gcTime is 5 minutes (5 * 60 * 1000 milliseconds) [1][6]. During Server-Side Rendering (SSR), this defaults to Infinity to prevent premature data removal [6]. 4. Cleanup Process: If no new observers mount for that query key before the gcTime expires, the query is removed from the cache entirely [2][6]. If a new observer mounts while the query is still inactive (i.e., before the timer expires), the garbage collection process is cancelled, and the query returns to an active state [2]. If multiple instances of a query exist with different gcTime settings, the library uses the longest duration to ensure data availability [6]. You can set gcTime to Infinity to disable garbage collection for a specific query [6].
Citations:
Separate active-observer behavior from
gcTime.A case with another observer on the same Query key is different from ignored-signal behavior. With remaining observers, the query stays active until the last observer is removed; with an ignored signal, the unobserved request can finish and only later reach
gcTimewhile the data is inactive.Suggested wording
📝 Committable suggestion
🧰 Tools
🪛 LanguageTool
[style] ~292-~292: This phrase is redundant. Consider writing “same”.
Context: ...red, or another observer still uses the same exact Query key, the request may finish and r...
(SAME_EXACT)
🤖 Prompt for AI Agents
Source: MCP tools