Describe the bug
Hi, I am not sure this is an issue or intended behavior. Setting gcTimeon the queryCollectionOptions does not override the default gcTime on the tanstack/query.
This is my collection definition:
const collection = createCollection(
queryCollectionOptions({
queryKey: ["test"],
staleTime: Infinity,
gcTime: Infinity,
queryClient,
Checking tanstack query devtools the query is still using the gcTimefrom the queryClient.
I do get this warning when the query is cleaned up:
[cleanupQueryIfIdle] Invariant violation: refcount=1 but no listeners. Cleaning up to prevent leak. {hashedQueryKey: '["test"]'}
Trying to ship a fix for this and ran into a counterintuitive baseline. Locally on
main, the following test passes without any source change:```ts it(`should forward gcTime from queryCollectionOptions to the underlying query`, async () => { const customQueryClient = new QueryClient({ defaultOptions: { queries: { gcTime: 60000, staleTime: 0 } }, }) const queryKey = [`gcTimeForwardTest`] const config: QueryCollectionConfig = { id: `gcTimeForwardTest`, queryClient: customQueryClient, queryKey, queryFn: vi.fn().mockResolvedValue([{ id: `1`, name: `Item 1` }]), getKey, startSync: true, gcTime: Infinity, } const collection = createCollection(queryCollectionOptions(config)) await vi.waitFor(() => expect(collection.status).toBe(`ready`)) const query = customQueryClient.getQueryCache().find({ queryKey }) expect((query?.options as any).gcTime).toBe(Infinity) // <-- passes on main }) ```
Reading `packages/query-db-collection/src/query.ts:571-588`, `gcTime` is not in the destructure list, so it flows into `...baseCollectionConfig` and ends up on the returned `CollectionConfig` (the spread at `L1932`). The observer-options block at `L1147-1166` does NOT include `gcTime` next to `staleTime`, yet the cache entry still reports the user-supplied value. There must be a forwarding path I'm missing (probably the Collection itself reads `config.gcTime` and the underlying query observer ends up with it via a route that's not the explicit `observerOptions` spread).
A few clarifying questions for @fehmer to make sure we're fixing the same thing:
Happy to send a targeted PR once we agree on the exact failing path — would just like a repro that's red on `main` so we can ship a clean RED→GREEN fix.