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', () => {
76
76
} )
77
77
} )
78
78
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
+
79
101
function defineTest ( f : Fixture ) {
80
102
test ( 'basic' , async ( { page } ) => {
81
103
using _ = expectNoPageError ( page )
82
104
await page . goto ( f . url ( ) )
83
105
await waitForHydration ( page )
106
+ expect ( f . proc ( ) . stderr ( ) ) . toBe ( '' )
84
107
} )
85
108
86
109
test ( 'client component' , async ( { page } ) => {
Original file line number Diff line number Diff line change @@ -106,7 +106,7 @@ export function useFixture(options: {
106
106
await proc . done
107
107
assert ( proc . proc . exitCode === 0 )
108
108
}
109
- const proc = runCli ( {
109
+ proc = runCli ( {
110
110
command : options . command ?? `pnpm preview` ,
111
111
label : `${ options . root } :preview` ,
112
112
cwd,
Original file line number Diff line number Diff line change @@ -951,6 +951,24 @@ function vitePluginUseClient(
951
951
const browserEnvironmentName =
952
952
useClientPluginOptions . environment ?. browser ?? 'client'
953
953
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
+
954
972
return [
955
973
{
956
974
name : 'rsc:use-client' ,
@@ -986,7 +1004,9 @@ function vitePluginUseClient(
986
1004
`[vite-rsc] detected an internal client boundary created by a package imported on rsc environment` ,
987
1005
)
988
1006
}
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 ) } `
990
1010
referenceKey = importId
991
1011
} else if ( packageSource ) {
992
1012
if ( this . environment . mode === 'dev' ) {
You can’t perform that action at this time.
0 commit comments