Skip to content

Comments

fix(query-core): remove isServer check from refetch interval logic#10164

Open
darshjme-codes wants to merge 1 commit intoTanStack:mainfrom
darshjme-codes:fix/isserver-check-breaking-extensions
Open

fix(query-core): remove isServer check from refetch interval logic#10164
darshjme-codes wants to merge 1 commit intoTanStack:mainfrom
darshjme-codes:fix/isserver-check-breaking-extensions

Conversation

@darshjme-codes
Copy link

@darshjme-codes darshjme-codes commented Feb 22, 2026

Fixes #10139

Problem

The isServer check in QueryObserver's #updateStaleTimeout and #updateRefetchInterval methods prevents refetch intervals from running in environments where window is undefined, such as:

  • Chrome extensions
  • VSCode extensions
  • Electron renderer processes
  • Any environment where globalThis.window is undefined

This occurs because isServer is defined as:

typeof window === 'undefined' || 'Deno' in globalThis

These environments are NOT servers but have no window global, causing the isServer check to incorrectly skip interval setup.

Solution

Remove the isServer check from both timeout methods. This is safe because:

  1. QueryObserver subscriptions only run on the client - they execute in React effects/useSyncExternalStore, never on the server
  2. The isServer check is redundant - if code reaches these methods, we're already on the client
  3. Other guards provide sufficient protection - enabled check, timeout validation, etc.

Changes

  • Removed isServer || check from #updateStaleTimeout (line 361)
  • Removed isServer || check from #updateRefetchInterval (line 392)

Impact

Fixes: Refetch intervals now work in Chrome/VSCode extensions
Maintains: Existing behavior for normal browser environments
No server impact: Code never runs on server anyway

Testing

This fix should be tested in:

  • Chrome extension environment
  • VSCode extension environment
  • Normal browser environment (regression test)
  • SSR/server environment (should have no change - code doesn't run there)

As suggested by @TkDodo in #4018 (reply in thread)

Summary by CodeRabbit

  • Refactor
    • Simplified internal timing conditions by removing server environment-specific handling, ensuring more consistent behavior across platforms.

Fixes TanStack#10139

## Problem
The isServer check in QueryObserver's #updateStaleTimeout and
#updateRefetchInterval methods prevents refetch intervals from
running in environments where window is undefined, such as:
- Chrome extensions
- VSCode extensions
- Electron renderer processes

This occurs because isServer is defined as:
  typeof window === 'undefined' || 'Deno' in globalThis

These environments are NOT servers but have no window global,
causing the isServer check to incorrectly skip interval setup.

## Solution
Remove the isServer check from both timeout methods. This is safe
because:
1. QueryObserver subscriptions only run on the client (they execute
   in React effects/useSyncExternalStore, never on the server)
2. The isServer check is redundant - if code reaches these methods,
   we're already on the client
3. Other guards (enabled check, timeout validation) provide
   sufficient protection

## Impact
- Fixes refetch intervals in Chrome/VSCode extensions
- Maintains existing behavior for normal browser environments
- No server-side impact (code never runs on server anyway)

Suggested by @TkDodo in discussion TanStack#4018
@changeset-bot
Copy link

changeset-bot bot commented Feb 22, 2026

⚠️ No Changeset found

Latest commit: 5d39628

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 22, 2026

📝 Walkthrough

Walkthrough

Removed isServer checks from two timing path conditions in queryObserver, decoupling stale timeout and refetch interval logic from server environment detection. These operations now depend solely on configuration validity and result state, allowing refetch mechanisms to function in extension environments like VSCode and Chrome.

Changes

Cohort / File(s) Summary
Query Observer Timing Logic
packages/query-core/src/queryObserver.ts
Removed isServer gating from #updateStaleTimeout and #updateRefetchInterval early-return conditions; timing operations now depend on result staleness, stale timeout validity, enabled state, and interval configuration only.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A tiny hop, a grand fix made,
Removing gates where servers played,
Extensions dance in browser light,
No more false checks to block their flight! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: removing the isServer check from refetch interval logic in query-core.
Description check ✅ Passed The PR description includes comprehensive context with problem statement, solution rationale, specific changes, and testing recommendations aligned with the template.
Linked Issues check ✅ Passed The code changes directly address issue #10139 by removing the isServer check from both updateStaleTimeout and updateRefetchInterval, enabling refetch intervals in extension environments.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the isServer check issue; no unrelated modifications were introduced.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/query-core/src/queryObserver.ts (1)

7-7: ⚠️ Potential issue | 🟡 Minor

Remove the unused isServer import introduced by this PR.

The isServer variable was removed from both #updateStaleTimeout (line 361) and #updateRefetchInterval (lines 391–397) in this PR, but the import on line 7 was not cleaned up. Since the project's root tsconfig.json has noUnusedLocals: true enabled, this will cause a build failure.

🧹 Cleanup
 import {
-  isServer,
   isValidTimeout,
   noop,
   replaceData,
   resolveEnabled,
   resolveStaleTime,
   shallowEqualObjects,
   timeUntilStale,
 } from './utils'
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/query-core/src/queryObserver.ts` at line 7, Remove the now-unused
isServer import from the import list in queryObserver.ts; since isServer was
removed from the private methods `#updateStaleTimeout` and `#updateRefetchInterval`,
delete isServer from the top-level imports to satisfy noUnusedLocals and avoid
the build failure.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@packages/query-core/src/queryObserver.ts`:
- Line 7: Remove the now-unused isServer import from the import list in
queryObserver.ts; since isServer was removed from the private methods
`#updateStaleTimeout` and `#updateRefetchInterval`, delete isServer from the
top-level imports to satisfy noUnusedLocals and avoid the build failure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tanstack Query refetch does not work in certain environments (vscode extension, chrome extension)

1 participant