File tree Expand file tree Collapse file tree 3 files changed +45
-2
lines changed
Expand file tree Collapse file tree 3 files changed +45
-2
lines changed Original file line number Diff line number Diff line change @@ -76,11 +76,34 @@ test.describe('dev-non-optimized-cjs', () => {
7676 } )
7777} )
7878
79+ test . describe ( 'dev-inconsistent-client-optimization' , ( ) => {
80+ test . beforeAll ( async ( ) => {
81+ // remove explicitly added optimizeDeps.exclude
82+ const editor = f . createEditor ( 'vite.config.ts' )
83+ editor . edit ( ( s ) =>
84+ s . replace ( `'@vitejs/test-dep-client-in-server2/client',` , `` ) ,
85+ )
86+ } )
87+
88+ const f = useFixture ( {
89+ root : 'examples/basic' ,
90+ mode : 'dev' ,
91+ } )
92+
93+ test ( 'show warning' , async ( { page } ) => {
94+ await page . goto ( f . url ( ) )
95+ expect ( f . proc ( ) . stderr ( ) ) . toContain (
96+ 'client component dependency is inconsistently optimized.' ,
97+ )
98+ } )
99+ } )
100+
79101function defineTest ( f : Fixture ) {
80102 test ( 'basic' , async ( { page } ) => {
81103 using _ = expectNoPageError ( page )
82104 await page . goto ( f . url ( ) )
83105 await waitForHydration ( page )
106+ expect ( f . proc ( ) . stderr ( ) ) . toBe ( '' )
84107 } )
85108
86109 test ( 'client component' , async ( { page } ) => {
Original file line number Diff line number Diff line change @@ -106,7 +106,7 @@ export function useFixture(options: {
106106 await proc . done
107107 assert ( proc . proc . exitCode === 0 )
108108 }
109- const proc = runCli ( {
109+ proc = runCli ( {
110110 command : options . command ?? `pnpm preview` ,
111111 label : `${ options . root } :preview` ,
112112 cwd,
Original file line number Diff line number Diff line change @@ -951,6 +951,24 @@ function vitePluginUseClient(
951951 const browserEnvironmentName =
952952 useClientPluginOptions . environment ?. browser ?? 'client'
953953
954+ // TODO: warning for late optimizer discovery
955+ function warnInoncistentClientOptimization (
956+ ctx : Rollup . TransformPluginContext ,
957+ id : string ,
958+ ) {
959+ const { depsOptimizer } = server . environments . client
960+ if ( depsOptimizer ) {
961+ for ( const dep of Object . values ( depsOptimizer . metadata . optimized ) ) {
962+ if ( dep . src === id ) {
963+ ctx . warn (
964+ `client component dependency is inconsistently optimized. ` +
965+ `It's recommended to add the dependency to 'optimizeDeps.exclude'.` ,
966+ )
967+ }
968+ }
969+ }
970+ }
971+
954972 return [
955973 {
956974 name : 'rsc:use-client' ,
@@ -986,7 +1004,9 @@ function vitePluginUseClient(
9861004 `[vite-rsc] detected an internal client boundary created by a package imported on rsc environment` ,
9871005 )
9881006 }
989- importId = `/@id/__x00__virtual:vite-rsc/client-in-server-package-proxy/${ encodeURIComponent ( cleanUrl ( id ) ) } `
1007+ id = cleanUrl ( id )
1008+ warnInoncistentClientOptimization ( this , id )
1009+ importId = `/@id/__x00__virtual:vite-rsc/client-in-server-package-proxy/${ encodeURIComponent ( id ) } `
9901010 referenceKey = importId
9911011 } else if ( packageSource ) {
9921012 if ( this . environment . mode === 'dev' ) {
You can’t perform that action at this time.
0 commit comments