bug [upstream]: queryCollection does not refetch in non-windowed environments (Chrome extension, vscode extension)
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 3.9k
- Forks
- 266
- Avg merge
- 1d 4h
- Merged PRs (30d)
- 55
Description
- I've validated the bug against the latest version of DB packages
Describe the bug
An upstream issue in Tanstack Query prevents Tanstack DB from operating correctly in environments missing
To Reproduce
Steps to reproduce the behavior:
Create any collection in an environment where globalThis.window is undefined
Expected behavior
Refetches occur
Additional context
(From @KyleAMathews)
Root cause: TanStack Query's QueryObserver.#updateRefetchInterval() has a hard guard:
if (isServer ...) { return }
where isServer = typeof window === 'undefined' 'Deno' in globalThis. In a VS Code extension (Node.js), window is undefined so the refetch interval timer is never created.
TanStack Query's own docs: The recommended non-browser setup (e.g., React Native guide) uses focusManager.setFocused() and onlineManager.setOnline(). But those don't help here — the isServer guard fires before the focusManager.isFocused() check, so it blocks entirely.
Upstream status: This is acknowledged as a limitation in TanStack/query Discussion #4018. Maintainer TkDodo said the isServer check should be decoupled from setInterval availability, but no fix has landed — still present on main.
Given this, the proper fix should be at the QueryClient configuration level where queryCollectionOptions creates the QueryObserver. Since isServer is a module-level constant we can import from @tanstack/query-core, the cleanest approach is: when isServer && refetchInterval is configured, set refetchIntervalInBackground: true and manage a simple interval ourselves using observer.refetch() — the public API TanStack Query provides for exactly this purpose.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at queryCollectionOptions, where the QueryObserver is created, and review the non-windowed behavior described in the TanStack Query upstream issue. Reproduce with globalThis.window undefined and verify that configured refetch intervals invoke observer.refetch() in Chrome or VS Code-style environments.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100