Skip to content
Source
Sign inSign up
TanStack/query

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

ClosedAdzerKI(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/12026/headopened View on GitHub

🎯 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.
    1. 🦋 Changeset detected

      Latest commit: 56cc6ee79d48f0c6fc04ef060082a499773a6ba0

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

      This PR includes changesets to release 24 packages
      NameType
      @tanstack/query-corePatch
      @tanstack/angular-query-experimentalPatch
      @tanstack/lit-queryPatch
      @tanstack/preact-queryPatch
      @tanstack/query-async-storage-persisterPatch
      @tanstack/query-broadcast-client-experimentalPatch
      @tanstack/query-devtoolsPatch
      @tanstack/query-persist-client-corePatch
      @tanstack/query-sync-storage-persisterPatch
      @tanstack/react-queryPatch
      @tanstack/solid-queryPatch
      @tanstack/svelte-queryPatch
      @tanstack/vue-queryPatch
      @tanstack/preact-query-devtoolsPatch
      @tanstack/preact-query-persist-clientPatch
      @tanstack/react-query-devtoolsPatch
      @tanstack/solid-query-devtoolsPatch
      @tanstack/svelte-query-devtoolsPatch
      @tanstack/vue-query-devtoolsPatch
      @tanstack/react-query-persist-clientPatch
      @tanstack/solid-query-persist-clientPatch
      @tanstack/svelte-query-persist-clientPatch
      @tanstack/react-query-next-experimentalPatch
      @tanstack/eslint-plugin-queryPatch

      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

    2. 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 a8af0e243af6f09d670ea2ec9849c4e3e3bc17ed and 56cc6ee79d48f0c6fc04ef060082a499773a6ba0.

      📒 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 nameStatusExplanation
      Title checkPassedThe title clearly and concisely describes the main change: preventing garbage-collection scheduling on the server in query-core.
      Description checkPassedThe description covers the change and motivation, references the linked issue, completes the required checklist, and records the release impact with a changeset.
      Linked Issues checkPassedIssue [#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 checkPassedThe 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 CoveragePassedNo 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.
    3. TkDodo closed this

Sign in to join this conversation.