File tree Expand file tree Collapse file tree 8 files changed +109
-9
lines changed Expand file tree Collapse file tree 8 files changed +109
-9
lines changed Original file line number Diff line number Diff line change @@ -11,9 +11,6 @@ import {
1111import path from 'node:path'
1212import os from 'node:os'
1313
14- // TODO: parallel?
15- // TODO: all tests don't need to be tested in all variants?
16-
1714test . describe ( 'dev-default' , ( ) => {
1815 const f = useFixture ( { root : 'examples/basic' , mode : 'dev' } )
1916 defineTest ( f )
@@ -824,6 +821,14 @@ function defineTest(f: Fixture) {
824821 )
825822 } )
826823
824+ test ( 'transitive cjs dep' , async ( { page } ) => {
825+ await page . goto ( f . url ( ) )
826+ await waitForHydration ( page )
827+ await expect ( page . getByTestId ( 'transitive-cjs-client' ) ) . toHaveText (
828+ 'ok:browser' ,
829+ )
830+ } )
831+
827832 test ( 'use cache function' , async ( { page } ) => {
828833 await page . goto ( f . url ( ) )
829834 await waitForHydration ( page )
Original file line number Diff line number Diff line change 2121 "@types/react" : " ^19.1.8" ,
2222 "@types/react-dom" : " ^19.1.6" ,
2323 "@vitejs/plugin-react" : " latest" ,
24+ "@vitejs/test-dep-transitive-cjs" : " file:./test-dep/transitive-cjs" ,
2425 "@vitejs/test-dep-client-in-server" : " file:./test-dep/client-in-server" ,
2526 "@vitejs/test-dep-client-in-server2" : " file:./test-dep/client-in-server2" ,
2627 "@vitejs/test-dep-server-in-client" : " file:./test-dep/server-in-client" ,
Original file line number Diff line number Diff line change 1+ 'use client'
2+
3+ // @ts -ignore
4+ import { TestClient } from '@vitejs/test-dep-transitive-cjs/client'
5+
6+ export function TestTransitiveCjsClient ( ) {
7+ return (
8+ < div >
9+ [test-dep-transitive-cjs-client: < TestClient /> ]
10+ </ div >
11+ )
12+ }
Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ import { TestTemporaryReference } from './temporary-reference/client'
2929import { TestUseCache } from './use-cache/server'
3030import { TestHydrationMismatch } from './hydration-mismatch/server'
3131import { TestBrowserOnly } from './browser-only/client'
32+ import { TestTransitiveCjsClient } from './deps/transitive-cjs/client'
3233
3334export function Root ( props : { url : URL } ) {
3435 return (
@@ -67,6 +68,7 @@ export function Root(props: { url: URL }) {
6768 < TestClientInServer />
6869 < TestServerInServer />
6970 < TestServerInClient />
71+ < TestTransitiveCjsClient />
7072 < TestActionStateServer />
7173 < TestModuleInvalidationServer />
7274 < TestBrowserOnly />
Original file line number Diff line number Diff line change 1+ 'use client'
2+
3+ import React from 'react'
4+
5+ // similar to swr
6+ // https://github.com/vercel/swr/blob/063fe55dddb95f0b6c3f1637a935c43d732ded78/src/index/use-swr.ts#L3
7+ import { useSyncExternalStore } from 'use-sync-external-store/shim/index.js'
8+
9+ const h = React . createElement
10+
11+ const noopStore = ( ) => ( ) => { }
12+
13+ export function TestClient ( ) {
14+ const value = useSyncExternalStore (
15+ noopStore ,
16+ ( ) => 'ok:browser' ,
17+ ( ) => 'ok:ssr' ,
18+ )
19+
20+ return h (
21+ 'span' ,
22+ {
23+ 'data-testid' : 'transitive-cjs-client' ,
24+ } ,
25+ value ,
26+ )
27+ }
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " @vitejs/test-dep-transitive-cjs" ,
3+ "private" : true ,
4+ "type" : " module" ,
5+ "exports" : {
6+ "./client" : " ./client.js"
7+ },
8+ "dependencies" : {
9+ "use-sync-external-store" : " ^1.5.0"
10+ },
11+ "peerDependencies" : {
12+ "react" : " *"
13+ }
14+ }
Original file line number Diff line number Diff line change @@ -135,12 +135,29 @@ export default { fetch: handler };
135135 minify : false ,
136136 manifest : true ,
137137 } ,
138- optimizeDeps : {
139- exclude : [
140- '@vitejs/test-dep-client-in-server/client' ,
141- '@vitejs/test-dep-client-in-server2/client' ,
142- '@vitejs/test-dep-server-in-client/client' ,
143- ] ,
138+ environments : {
139+ client : {
140+ optimizeDeps : {
141+ entries : [
142+ './src/routes/**/client.tsx' ,
143+ './src/framework/entry.browser.tsx' ,
144+ ] ,
145+ exclude : [
146+ '@vitejs/test-dep-client-in-server/client' ,
147+ '@vitejs/test-dep-client-in-server2/client' ,
148+ '@vitejs/test-dep-server-in-client/client' ,
149+ ] ,
150+ } ,
151+ } ,
152+ ssr : {
153+ optimizeDeps : {
154+ // TODO: this should be somehow auto inferred or at least show a warning
155+ // to guide users to `optimizeDeps.include`
156+ include : [
157+ '@vitejs/test-dep-transitive-cjs > use-sync-external-store/shim/index.js' ,
158+ ] ,
159+ } ,
160+ } ,
144161 } ,
145162} ) as any
146163
You can’t perform that action at this time.
0 commit comments