Skip to content

fix(query-db-collection): forward gcTime from queryCollectionOptions to the underlying query#1568

Draft
spokodev wants to merge 1 commit into
TanStack:mainfrom
spokodev:fix/query-collection-forward-gc-and-stale-time
Draft

fix(query-db-collection): forward gcTime from queryCollectionOptions to the underlying query#1568
spokodev wants to merge 1 commit into
TanStack:mainfrom
spokodev:fix/query-collection-forward-gc-and-stale-time

Conversation

@spokodev
Copy link
Copy Markdown

@spokodev spokodev commented Jun 4, 2026

The queryCollectionOptions config exposes a gcTime knob in its type, but the value never reaches the underlying TanStack Query observer. As @fehmer noted on #1546, the devtools panel shows the query falling back to the queryClient default instead of the override.

At packages/query-db-collection/src/query.ts:1167, the observerOptions block conditionally spreads enabled, refetchInterval, retry, retryDelay, and staleTime from the config, but gcTime is missing from the destructure on line 580 and from the conditional spread. Adding it preserves the documented behavior.

// src/query.ts
   const {
     ...
     staleTime,
+    gcTime,
     persistedGcTime,
     ...
   } = config

   // ...

   const observerOptions: QueryObserverOptions<...> = {
     ...
     ...(staleTime !== undefined && { staleTime }),
+    ...(gcTime !== undefined && { gcTime }),
   }

The public QueryCollectionConfig type also gets a gcTime field next to staleTime, mirroring the same QueryObserverOptions[gcTime] reference.

Tests cover the forwarding path (override reaches the observer), the default fallback (omitted gcTime → queryClient default preserved), and gcTime: Infinity (the exact value @fehmer reported using). The forwarding and Infinity tests fail on master and pass with the fix; the fallback test passes on both because the existing behavior is preserved.

Closes #1546

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 4, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9e572e55-8c4f-4b30-8e9e-a2755feb006b

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

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.

query-collection gcTime not set to underlaying query

1 participant