Skip to content

fix: stop node types from leaking into browser#10302

Merged
TkDodo merged 1 commit intomainfrom
feature/node-types
Mar 20, 2026
Merged

fix: stop node types from leaking into browser#10302
TkDodo merged 1 commit intomainfrom
feature/node-types

Conversation

@TkDodo
Copy link
Collaborator

@TkDodo TkDodo commented Mar 20, 2026

fixes #10294

Summary by CodeRabbit

  • Bug Fixes
    • Fixed Node.js type definitions from leaking into browser environments for @tanstack/preact-query, @tanstack/react-query, and @tanstack/solid-query packages.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 20, 2026

📝 Walkthrough

Walkthrough

This pull request addresses a bug where Node.js types were leaking into browser environments by excluding test directories from production TypeScript configurations across three packages. A changeset file documents the corresponding patch releases.

Changes

Cohort / File(s) Summary
Changeset
.changeset/two-cameras-wear.md
New changeset documenting patch releases for @tanstack/preact-query, @tanstack/react-query, and @tanstack/solid-query to fix Node.js type leakage into browser environments.
TypeScript Production Configs
packages/preact-query/tsconfig.prod.json, packages/react-query/tsconfig.prod.json, packages/solid-query/tsconfig.prod.json
Added exclude: ["src/__tests__"] configuration to prevent test files from being included in production build scope and type declarations.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 Types were leaking far and wide,
Node.js hiding in the browser tide,
A simple exclude, a test-free zone,
Now client projects stand alone!
Types are pure, the fix is done,
Browser builds in the sun! ☀️

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is minimal (only 'fixes #10294') and does not follow the repository's template which requires sections for Changes, Checklist, and Release Impact. Expand the description to include the template sections: explain the changes made, confirm testing, and note the changeset for the release.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely summarizes the main objective of the PR: preventing Node.js types from leaking into browser environments.
Linked Issues check ✅ Passed The code changes directly address issue #10294 by excluding test files from production TypeScript configs, preventing Node.js types from leaking into browser builds.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the Node.js type leakage issue: tsconfig.prod.json updates across three packages and a changeset file documenting the fix.
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 unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/node-types
📝 Coding Plan
  • Generate coding plan for human review comments

Comment @coderabbitai help to get the list of available commands and usage tips.

@nx-cloud
Copy link

nx-cloud bot commented Mar 20, 2026

View your CI Pipeline Execution ↗ for commit 2e0aae8

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 2m 40s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 1s View ↗

☁️ Nx Cloud last updated this comment at 2026-03-20 12:21:34 UTC

@github-actions
Copy link
Contributor

🚀 Changeset Version Preview

3 package(s) bumped directly, 0 bumped as dependents.

🟩 Patch bumps

Package Version Reason
@tanstack/preact-query 5.94.2 → 5.94.3 Changeset
@tanstack/react-query 5.91.2 → 5.91.3 Changeset
@tanstack/solid-query 5.91.3 → 5.91.4 Changeset

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 20, 2026

More templates

@tanstack/angular-query-experimental

npm i https://pkg.pr.new/@tanstack/angular-query-experimental@10302

@tanstack/eslint-plugin-query

npm i https://pkg.pr.new/@tanstack/eslint-plugin-query@10302

@tanstack/preact-query

npm i https://pkg.pr.new/@tanstack/preact-query@10302

@tanstack/preact-query-devtools

npm i https://pkg.pr.new/@tanstack/preact-query-devtools@10302

@tanstack/preact-query-persist-client

npm i https://pkg.pr.new/@tanstack/preact-query-persist-client@10302

@tanstack/query-async-storage-persister

npm i https://pkg.pr.new/@tanstack/query-async-storage-persister@10302

@tanstack/query-broadcast-client-experimental

npm i https://pkg.pr.new/@tanstack/query-broadcast-client-experimental@10302

@tanstack/query-core

npm i https://pkg.pr.new/@tanstack/query-core@10302

@tanstack/query-devtools

npm i https://pkg.pr.new/@tanstack/query-devtools@10302

@tanstack/query-persist-client-core

npm i https://pkg.pr.new/@tanstack/query-persist-client-core@10302

@tanstack/query-sync-storage-persister

npm i https://pkg.pr.new/@tanstack/query-sync-storage-persister@10302

@tanstack/react-query

npm i https://pkg.pr.new/@tanstack/react-query@10302

@tanstack/react-query-devtools

npm i https://pkg.pr.new/@tanstack/react-query-devtools@10302

@tanstack/react-query-next-experimental

npm i https://pkg.pr.new/@tanstack/react-query-next-experimental@10302

@tanstack/react-query-persist-client

npm i https://pkg.pr.new/@tanstack/react-query-persist-client@10302

@tanstack/solid-query

npm i https://pkg.pr.new/@tanstack/solid-query@10302

@tanstack/solid-query-devtools

npm i https://pkg.pr.new/@tanstack/solid-query-devtools@10302

@tanstack/solid-query-persist-client

npm i https://pkg.pr.new/@tanstack/solid-query-persist-client@10302

@tanstack/svelte-query

npm i https://pkg.pr.new/@tanstack/svelte-query@10302

@tanstack/svelte-query-devtools

npm i https://pkg.pr.new/@tanstack/svelte-query-devtools@10302

@tanstack/svelte-query-persist-client

npm i https://pkg.pr.new/@tanstack/svelte-query-persist-client@10302

@tanstack/vue-query

npm i https://pkg.pr.new/@tanstack/vue-query@10302

@tanstack/vue-query-devtools

npm i https://pkg.pr.new/@tanstack/vue-query-devtools@10302

commit: 2e0aae8

@github-actions
Copy link
Contributor

size-limit report 📦

Path Size
react full 11.98 KB (0%)
react minimal 9.01 KB (0%)

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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/react-query/tsconfig.prod.json`:
- Line 8: Add test folders to the production TypeScript config's exclude list so
test-only types don't leak into browser type definitions: update
tsconfig.prod.json's "exclude" array to include the test pattern (e.g.,
"src/__tests__" or other test dirs/patterns used in this package) so that test
infra and Node-dependent types are omitted from generated production typings.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 36dd1226-5f9a-42e1-accf-de18ae1ae78a

📥 Commits

Reviewing files that changed from the base of the PR and between e79176a and 2e0aae8.

📒 Files selected for processing (4)
  • .changeset/two-cameras-wear.md
  • packages/preact-query/tsconfig.prod.json
  • packages/react-query/tsconfig.prod.json
  • packages/solid-query/tsconfig.prod.json

"rootDir": "../../"
}
},
"exclude": ["src/__tests__"]
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Verify that tests contain Node-specific types and production sources don't.

# Check if test files reference Node-specific types
rg -t ts -t tsx -C3 'NodeJS\.' 'packages/react-query/src/__tests__'

# Look for Node-specific module imports in tests
rg -t ts -t tsx -C3 "from ['\"]node:" 'packages/react-query/src/__tests__'

# Verify production source files don't import Node types directly
rg -t ts -t tsx -C3 'NodeJS\.' 'packages/react-query/src' -g '!**/__tests__/**'

Repository: TanStack/query

Length of output: 141


🏁 Script executed:

#!/bin/bash
# Description: Verify that tests contain Node-specific types and production sources don't.

# First, check the tsconfig.prod.json content
echo "=== tsconfig.prod.json content ==="
cat packages/react-query/tsconfig.prod.json

echo -e "\n=== Checking for Node-specific types in test files ==="
# Check if test files reference Node-specific types (adjusted syntax)
rg 'NodeJS\.' packages/react-query/src/__tests__ || echo "No NodeJS. references found in tests"

echo -e "\n=== Checking for node module imports in test files ==="
# Look for Node-specific module imports in tests
rg "from ['\"]node:" packages/react-query/src/__tests__ || echo "No node: imports found in tests"

echo -e "\n=== Checking if production source files import Node types ==="
# Verify production source files don't import Node types directly
rg 'NodeJS\.' packages/react-query/src --glob='!**/__tests__/**' || echo "No NodeJS. references found in production sources"

Repository: TanStack/query

Length of output: 555


🏁 Script executed:

#!/bin/bash
echo "=== Checking preact-query tsconfig.prod.json ==="
cat packages/preact-query/tsconfig.prod.json 2>/dev/null || echo "File not found"

echo -e "\n=== Examining actual imports in react-query test files ==="
# Look at what test files import (sample a few)
find packages/react-query/src/__tests__ -type f \( -name "*.ts" -o -name "*.tsx" \) -print -exec head -20 {} \; | head -100

echo -e "\n=== Checking for `@types/node` or similar in test files ==="
rg '@types/node|NodeJS|vitest|jest' packages/react-query/src/__tests__ --max-count=10

Repository: TanStack/query

Length of output: 8475


🏁 Script executed:

#!/bin/bash
echo "=== Checking vitest package.json ==="
cat node_modules/vitest/package.json | grep -A5 '"types"\|"typings"' | head -10

echo -e "\n=== Checking what vitest exports ==="
head -50 node_modules/vitest/dist/index.d.ts 2>/dev/null || echo "Index file not found, checking alternatives..."
find node_modules/vitest -name "*.d.ts" -type f | head -5

echo -e "\n=== Checking if Node types appear in vitest ==="
rg 'import.*from ["\']node' node_modules/vitest/dist/ --max-count=5 2>/dev/null || echo "Not found or inaccessible"

echo -e "\n=== Checking git history for this tsconfig.prod.json change ==="
git log --oneline -n 20 -- packages/react-query/tsconfig.prod.json

Repository: TanStack/query

Length of output: 435


🏁 Script executed:

#!/bin/bash
echo "=== Git history for tsconfig.prod.json ==="
git log --oneline -10 -- packages/react-query/tsconfig.prod.json

echo -e "\n=== Check when this exclude was added ==="
git log -p --follow -S 'src/__tests__' -- packages/react-query/tsconfig.prod.json | head -100

echo -e "\n=== Check if there's a corresponding preact-query change ==="
git log --oneline -5 -- packages/preact-query/tsconfig.prod.json

echo -e "\n=== Verify the PR context if available ==="
git log --grep="exclude\|tests\|tsconfig" --oneline | head -10

Repository: TanStack/query

Length of output: 361


🏁 Script executed:

#!/bin/bash
echo "=== Details of the commit that added this change ==="
git show 2e0aae80 --stat

echo -e "\n=== Full commit message and changes ==="
git show 2e0aae80 | head -200

Repository: TanStack/query

Length of output: 50371


Exclude test files from production type definitions to prevent Node.js type leakage.

This change mirrors the preact-query fix to ensure type definitions for browser environments don't include types from test infrastructure and dependencies that may depend on Node.js APIs.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/react-query/tsconfig.prod.json` at line 8, Add test folders to the
production TypeScript config's exclude list so test-only types don't leak into
browser type definitions: update tsconfig.prod.json's "exclude" array to include
the test pattern (e.g., "src/__tests__" or other test dirs/patterns used in this
package) so that test infra and Node-dependent types are omitted from generated
production typings.

@TkDodo TkDodo merged commit be3746f into main Mar 20, 2026
10 checks passed
@TkDodo TkDodo deleted the feature/node-types branch March 20, 2026 12:25
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.

@types/node types leak into browser/client projects in version 5.91.0

1 participant