File tree Expand file tree Collapse file tree 11 files changed +50
-6
lines changed Expand file tree Collapse file tree 11 files changed +50
-6
lines changed Original file line number Diff line number Diff line change @@ -1454,4 +1454,12 @@ function defineTest(f: Fixture) {
14541454 'test-chunk1|test-chunk2|test-chunk2b|test-chunk3|test-chunk3' ,
14551455 )
14561456 } )
1457+
1458+ test ( 'tree-shake2' , async ( { page } ) => {
1459+ await page . goto ( f . url ( ) )
1460+ await waitForHydration ( page )
1461+ await expect ( page . getByTestId ( 'test-tree-shake2' ) ) . toHaveText (
1462+ 'test-tree-shake2:lib-client1|lib-server1' ,
1463+ )
1464+ } )
14571465}
Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ import { TestAssetsServer } from './assets/server'
3939import { TestHmrSwitchServer } from './hmr-switch/server'
4040import { TestHmrSwitchClient } from './hmr-switch/client'
4141import { TestTreeShakeServer } from './tree-shake/server'
42+ import { TestTreeShake2 } from './tree-shake2/server'
4243import { TestClientChunkServer } from './chunk/server'
4344import { TestTailwind } from './tailwind'
4445import { TestHmrClientDep2 } from './hmr-client-dep2/client'
@@ -100,6 +101,7 @@ export function Root(props: { url: URL }) {
100101 < TestImportMetaGlob />
101102 < TestAssetsServer />
102103 < TestTreeShakeServer />
104+ < TestTreeShake2 />
103105 < TestClientChunkServer />
104106 < TestChunk2 />
105107 < TestUseId />
Original file line number Diff line number Diff line change 1+ 'use client'
2+
3+ export function LibClient1 ( ) {
4+ return 'lib-client1'
5+ }
Original file line number Diff line number Diff line change 1+ 'use client'
2+
3+ export function LibClient2 ( ) {
4+ return 'lib-client2:__unused_tree_shake2__'
5+ }
Original file line number Diff line number Diff line change 1+ export function LibServer1 ( ) {
2+ return 'lib-server1'
3+ }
Original file line number Diff line number Diff line change 1+ export function LibServer2 ( ) {
2+ return 'lib-server2:__unused_tree_shake2__'
3+ }
Original file line number Diff line number Diff line change 1+ export * from './lib-client1'
2+ export * from './lib-client2'
3+ export * from './lib-server1'
4+ export * from './lib-server2'
Original file line number Diff line number Diff line change 1+ import { LibClient1 , LibServer1 } from './lib'
2+
3+ export function TestTreeShake2 ( ) {
4+ return (
5+ < div data-testid = "test-tree-shake2" >
6+ test-tree-shake2:
7+ < LibClient1 /> |< LibServer1 />
8+ </ div >
9+ )
10+ }
Original file line number Diff line number Diff line change @@ -47,6 +47,7 @@ export default defineConfig({
4747 if ( chunk . type === 'chunk' ) {
4848 assert ( ! chunk . code . includes ( '__unused_client_reference__' ) )
4949 assert ( ! chunk . code . includes ( '__unused_server_export__' ) )
50+ assert ( ! chunk . code . includes ( '__unused_tree_shake2__' ) )
5051 }
5152 }
5253 } ,
Original file line number Diff line number Diff line change @@ -1226,12 +1226,14 @@ function vitePluginUseClient(
12261226 // group client reference modules by `clientChunks` option
12271227 manager . clientReferenceGroups = { }
12281228 for ( const meta of Object . values ( manager . clientReferenceMetaMap ) ) {
1229+ // no server chunk is associated when the entire "use client" module is tree-shaken
1230+ if ( ! meta . serverChunk ) continue
12291231 let name =
12301232 useClientPluginOptions . clientChunks ?.( {
12311233 id : meta . importId ,
12321234 normalizedId : manager . toRelativeId ( meta . importId ) ,
1233- serverChunk : meta . serverChunk ! ,
1234- } ) ?? meta . serverChunk !
1235+ serverChunk : meta . serverChunk ,
1236+ } ) ?? meta . serverChunk
12351237 // ensure clean virtual id to avoid interfering with other plugins
12361238 name = cleanUrl ( name . replaceAll ( '..' , '__' ) )
12371239 const group = ( manager . clientReferenceGroups [ name ] ??= [ ] )
@@ -1333,6 +1335,7 @@ function vitePluginUseClient(
13331335 }
13341336 } ,
13351337 generateBundle ( _options , bundle ) {
1338+ if ( manager . isScanBuild ) return
13361339 if ( this . environment . name !== serverEnvironmentName ) return
13371340
13381341 // analyze rsc build to inform later client reference building.
You can’t perform that action at this time.
0 commit comments