11import { render , screen } from '@testing-library/react'
22import { describe , expect , it } from 'vitest'
3+ import { getIsomorphicEnv } from '../src/isomorphic'
34import { Counter } from '../src/components/Counter'
45
56/**
67 * This test verifies that the tanstackStart() vite plugin works correctly
7- * with Vitest. Without the fix in PR #6074, the optimizeDeps configuration
8- * would cause React to be pre-bundled incorrectly, leading to "Invalid hook
9- * call" errors when rendering components that use React hooks.
8+ * with Vitest without forcing us to disable the plugin entirely.
9+ *
10+ * Without the fix in PR #6074, optimizeDeps caused React to be pre-bundled
11+ * incorrectly, leading to "Invalid hook call" errors. Disabling the plugin
12+ * avoids that error, but then createIsomorphicFn() is never transformed and
13+ * becomes a no-op that returns undefined.
1014 *
1115 * The fix adds `process.env.VITEST !== 'true'` to disable optimizeDeps
12- * in Vitest environments.
16+ * in Vitest while keeping the plugin enabled, so hooks and createIsomorphicFn
17+ * both work as expected.
1318 */
1419describe ( 'Vitest with tanstackStart() plugin' , ( ) => {
1520 it ( 'renders a component using React hooks without errors' , ( ) => {
@@ -18,4 +23,8 @@ describe('Vitest with tanstackStart() plugin', () => {
1823 render ( < Counter /> )
1924 expect ( screen . getByRole ( 'button' ) ) . toHaveTextContent ( 'Count: 0' )
2025 } )
26+
27+ it ( 'selects the client implementation for createIsomorphicFn()' , ( ) => {
28+ expect ( getIsomorphicEnv ( ) ) . toBe ( 'client' )
29+ } )
2130} )
0 commit comments