Skip to content

Conversation

@RawToast
Copy link
Contributor

@RawToast RawToast commented Oct 17, 2025

Currently tests using vitest fail to run giving an error of: TypeError: Cannot read properties of null (reading 'useState')

TypeError: Cannot read properties of null (reading 'useState')
 ❯ exports.useState node_modules/react/cjs/react.development.js:1263:32
 ❯ StateButton src/components/StateButton.tsx:5:29

Recreated in this example

What's more revealing is the "rules of hooks" warnings above the test, which could indicate something being loaded twice:

stderr | src/components/__tests__/StateButton.test.tsx > StateButton > should increment
Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
See https://react.dev/link/invalid-hook-call for tips about how to debug and fix this problem.

These errors go away if the TanStack start plugin is removed from vite.config.js as mentioned here:
https://discord.com/channels/719702312431386674/1425117017140367421

I am no Vite plugin expert, but by simply removing the second react include line this issue was resolved for me. There may be a more elegant or correct solution than this, but hopefully this at least helps. I would have thought the dedupe lines above would've done the same task, so maybe this is not a bug here and could be a Vite issue instead 🤔

Summary by CodeRabbit

  • Chores
    • Optimized build configuration settings to streamline dependency optimization.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 17, 2025

Walkthrough

Removed 'react' from the optimizeDeps.include list in the Vite configuration for the react-start package. The entry 'react/jsx-runtime', 'react/jsx-dev-runtime', and 'react-dom' remain included for optimization, with only the main 'react' package excluded from forced optimization.

Changes

Cohort / File(s) Summary
Vite Configuration
packages/react-start/src/plugin/vite.ts
Removed 'react' from optimizeDeps.include list, reducing the set of force-included dependencies for pre-bundling while maintaining React subpath and react-dom entries

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Possibly related PRs

  • TanStack/router#5223: Modifies the same Vite optimizeDeps configuration in packages/react-start/src/plugin/vite.ts, adding optimizeDeps.entries and alias configurations alongside related dependency optimization changes.

Suggested labels

package: react-start

Poem

🐰 One 'react' hops away,
Optimized for a lighter day,
The jsx paths stay and play,
Pre-bundling finds a better way,
Bundler speed saves the day! 🚀

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "Fix for vitest hooks issue" is clearly related to the main objective of the changeset. The PR description and raw summary confirm that the changeset specifically addresses a vitest hooks runtime error where tests fail due to duplicate React copies causing "Invalid hook call" warnings. The title accurately describes the primary purpose of the change—fixing this vitest hooks issue—though it doesn't include the technical implementation detail (removing 'react' from optimizeDeps.include). The title is concise, specific, and a teammate scanning the history would understand that this PR resolves a vitest-related hooks problem.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between be6c094 and 0491dcd.

📒 Files selected for processing (1)
  • packages/react-start/src/plugin/vite.ts (0 hunks)
💤 Files with no reviewable changes (1)
  • packages/react-start/src/plugin/vite.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Test
  • GitHub Check: Preview

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.

@nx-cloud
Copy link

nx-cloud bot commented Oct 17, 2025

View your CI Pipeline Execution ↗ for commit 0491dcd

Command Status Duration Result
nx affected --targets=test:eslint,test:unit,tes... ✅ Succeeded 3m 27s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 8s View ↗

☁️ Nx Cloud last updated this comment at 2025-10-17 13:08:33 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 17, 2025

More templates

@tanstack/arktype-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/arktype-adapter@5508

@tanstack/directive-functions-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/directive-functions-plugin@5508

@tanstack/eslint-plugin-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/eslint-plugin-router@5508

@tanstack/history

npm i https://pkg.pr.new/TanStack/router/@tanstack/history@5508

@tanstack/nitro-v2-vite-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/nitro-v2-vite-plugin@5508

@tanstack/react-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router@5508

@tanstack/react-router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-devtools@5508

@tanstack/react-router-ssr-query

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-ssr-query@5508

@tanstack/react-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start@5508

@tanstack/react-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-client@5508

@tanstack/react-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server@5508

@tanstack/router-cli

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-cli@5508

@tanstack/router-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-core@5508

@tanstack/router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools@5508

@tanstack/router-devtools-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools-core@5508

@tanstack/router-generator

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-generator@5508

@tanstack/router-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-plugin@5508

@tanstack/router-ssr-query-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-ssr-query-core@5508

@tanstack/router-utils

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-utils@5508

@tanstack/router-vite-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-vite-plugin@5508

@tanstack/server-functions-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/server-functions-plugin@5508

@tanstack/solid-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router@5508

@tanstack/solid-router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-devtools@5508

@tanstack/solid-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start@5508

@tanstack/solid-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-client@5508

@tanstack/solid-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server@5508

@tanstack/start-client-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-client-core@5508

@tanstack/start-plugin-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-plugin-core@5508

@tanstack/start-server-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-core@5508

@tanstack/start-static-server-functions

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-static-server-functions@5508

@tanstack/start-storage-context

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-storage-context@5508

@tanstack/valibot-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/valibot-adapter@5508

@tanstack/virtual-file-routes

npm i https://pkg.pr.new/TanStack/router/@tanstack/virtual-file-routes@5508

@tanstack/zod-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/zod-adapter@5508

commit: 0491dcd

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.

1 participant