-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fix(react-start): Do not optimizeDeps in VITEST environment #6074
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
📝 WalkthroughWalkthroughAdds a Vitest-aware guard condition to the Vite plugin's optimizeDeps configuration in Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
|
View your CI Pipeline Execution ↗ for commit 9fae447
☁️ Nx Cloud last updated this comment at |
There was a problem hiding this 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
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/react-start/src/plugin/vite.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
Use TypeScript strict mode with extensive type safety for all code
Files:
packages/react-start/src/plugin/vite.ts
**/*.{js,ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
Implement ESLint rules for router best practices using the ESLint plugin router
Files:
packages/react-start/src/plugin/vite.ts
🧠 Learnings (1)
📚 Learning: 2025-11-02T16:16:24.898Z
Learnt from: nlynzaad
Repo: TanStack/router PR: 5732
File: packages/start-client-core/src/client/hydrateStart.ts:6-9
Timestamp: 2025-11-02T16:16:24.898Z
Learning: In packages/start-client-core/src/client/hydrateStart.ts, the `import/no-duplicates` ESLint disable is necessary for imports from `#tanstack-router-entry` and `#tanstack-start-entry` because both aliases resolve to the same placeholder file (`fake-start-entry.js`) in package.json during static analysis, even though they resolve to different files at runtime.
Applied to files:
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
|
Made a repro and an issue: #6246. The problem can be clearly seen there. This PR fixes it. |
3dc34cf to
79c06e4
Compare
|
Thanks @onlywei I hope @schiller-manuel is around today approve and merge. :-) |
He's most likely busy making awesome features like React Server Components work. I'll be patient and keep rebasing to resolve lockfile conflicts. |
Absolutely, and I'm using the workaround for now anyway. :-) |
Does |
We're not using any environment functions yet, so it's just the one basic server function using |
I see. Without the Tanstack start vite plugin enabled, it's hard for me to test any isomorphic function. |
78895fc to
b545524
Compare
b545524 to
9fae447
Compare
Why
Vitest + react-start currently forces
optimizeDepsto prebundle React, which can create dual React instances and break hooks. The workaround is disabling the plugin, but thencreateIsomorphicFn()is never transformed and becomes a no-op.Fixes #6246 and #6262
Dilemma
Without this fix, I have to give up using either
useState(),createIsomorphicFn(), or Vitest. I can’t use all three.Fix
Skip the aggressive
optimizeDepsconfiguration whenprocess.env.VITEST === 'true', so hooks work andcreateIsomorphicFn()still transforms.This is actually just a 1-line fix, the rest is just comments and an e2e test.
Verified
Vitest passes locally without workarounds.