fix: stop node types from leaking into browser#10302
Conversation
📝 WalkthroughWalkthroughThis 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
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Comment |
|
View your CI Pipeline Execution ↗ for commit 2e0aae8
☁️ Nx Cloud last updated this comment at |
🚀 Changeset Version Preview3 package(s) bumped directly, 0 bumped as dependents. 🟩 Patch bumps
|
size-limit report 📦
|
There was a problem hiding this comment.
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
📒 Files selected for processing (4)
.changeset/two-cameras-wear.mdpackages/preact-query/tsconfig.prod.jsonpackages/react-query/tsconfig.prod.jsonpackages/solid-query/tsconfig.prod.json
| "rootDir": "../../" | ||
| } | ||
| }, | ||
| "exclude": ["src/__tests__"] |
There was a problem hiding this comment.
🧩 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=10Repository: 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.jsonRepository: 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 -10Repository: 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 -200Repository: 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.
fixes #10294
Summary by CodeRabbit