Skip to content

Commit 9fae447

Browse files
committed
Add isomorphic test case for vitest-hooks e2e test
1 parent 84807a7 commit 9fae447

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { createIsomorphicFn } from '@tanstack/react-start'
2+
3+
export const getIsomorphicEnv = createIsomorphicFn()
4+
.client(() => 'client')
5+
.server(() => 'server')
Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
import { render, screen } from '@testing-library/react'
22
import { describe, expect, it } from 'vitest'
3+
import { getIsomorphicEnv } from '../src/isomorphic'
34
import { 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
*/
1419
describe('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

Comments
 (0)