Skip to content

fix(query-core): do not schedule garbage collection on the server - #12026

Open
AdzerKI wants to merge 1 commit into
TanStack:mainfrom
AdzerKI:fix/no-gc-timer-on-server
Open

AdzerKI wants to merge 1 commit into
TanStack:mainfrom
AdzerKI:fix/no-gc-timer-on-server

Conversation

@AdzerKI

@AdzerKI AdzerKI commented Oct 14, 2026 •

Copy link
Copy Markdown

🎯 Changes

On the server, scheduleGc now returns early, so no timer is scheduled even when gcTime is set explicitly (the gcTime value itself is still kept). Added a test and a patch changeset for @tanstack/query-core.

Fixes #12025

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested code changes locally with pnpm run test:pr, or these tests do not apply to this pull request.
  • I have followed the AI contribution policy and fully understand the code in this pull request, including any code generated with AI assistance.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • Bug Fixes
    • Garbage collection is no longer scheduled on the server, even when an explicit garbage-collection time is set. Client-side garbage collection continues to work as before.

@changeset-bot

changeset-bot Bot commented Oct 14, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 56cc6ee

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 24 packages
Name Type
@tanstack/query-core Patch
@tanstack/angular-query-experimental Patch
@tanstack/lit-query Patch
@tanstack/preact-query Patch
@tanstack/query-async-storage-persister Patch
@tanstack/query-broadcast-client-experimental Patch
@tanstack/query-devtools Patch
@tanstack/query-persist-client-core Patch
@tanstack/query-sync-storage-persister Patch
@tanstack/react-query Patch
@tanstack/solid-query Patch
@tanstack/svelte-query Patch
@tanstack/vue-query Patch
@tanstack/preact-query-devtools Patch
@tanstack/preact-query-persist-client Patch
@tanstack/react-query-devtools Patch
@tanstack/solid-query-devtools Patch
@tanstack/svelte-query-devtools Patch
@tanstack/vue-query-devtools Patch
@tanstack/react-query-persist-client Patch
@tanstack/solid-query-persist-client Patch
@tanstack/svelte-query-persist-client Patch
@tanstack/react-query-next-experimental Patch
@tanstack/eslint-plugin-query Patch

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

@coderabbitai

coderabbitai Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: TanStack/query/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 740f748c-f44b-4ef3-94fa-cafa92cba966
📥 Commits

Reviewing files that changed from the base of the PR and between a8af0e2 and 56cc6ee.

📒 Files selected for processing: 3
  • .changeset/quiet-timers-rest.md
  • packages/query-core/src/__tests__/query.test.tsx
  • packages/query-core/src/removable.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

📝 Walkthrough

Server-side query garbage collection no longer schedules a timeout when gcTime is explicitly set. A test verifies that the configured value remains set and that no timeout is scheduled.

Changes: Server-side garbage collection

Layer / File(s) Summary
Prevent server-side GC timers
packages/query-core/src/removable.ts, packages/query-core/src/__tests__/query.test.tsx, .changeset/quiet-timers-rest.md
scheduleGc now returns without scheduling a timeout on the server. The test checks this behavior with gcTime: 1000. The changeset records the patch.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: sukvvon

Merge Risk: ⚪ Minimal · up to 56cc6

Server-side queries retain their configured gcTime without scheduling GC timers, and the supplied test covers the explicit-value case. No actionable merge risk is evident.

Pre-merge checks: Passed 5
Passed Passed checks: 5 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: preventing garbage-collection scheduling on the server in query-core.
Description check Passed The description covers the change and motivation, references the linked issue, completes the required checklist, and records the release impact with a changeset.
Linked Issues check Passed Issue [#12025] requires no garbage-collection timer on the server for any gcTime value while retaining the value. Removable.scheduleGc() now clears an existing timeout and returns when `isServerEn…
Out of Scope Changes check Passed The changed implementation directly addresses server-side garbage-collection scheduling. The test covers the explicit gcTime case from issue [#12025]. The changeset documents the published `@tanstac…
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Explicit gcTime schedules a GC timer during SSR, retaining the whole render in memory

1 participant