-
Notifications
You must be signed in to change notification settings - Fork 172
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.