Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/plugin-rsc/e2e/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1454,4 +1454,12 @@ function defineTest(f: Fixture) {
'test-chunk1|test-chunk2|test-chunk2b|test-chunk3|test-chunk3',
)
})

test('tree-shake2', async ({ page }) => {
await page.goto(f.url())
await waitForHydration(page)
await expect(page.getByTestId('test-tree-shake2')).toHaveText(
'test-tree-shake2:lib-client1|lib-server1',
)
})
}
2 changes: 2 additions & 0 deletions packages/plugin-rsc/examples/basic/src/routes/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { TestAssetsServer } from './assets/server'
import { TestHmrSwitchServer } from './hmr-switch/server'
import { TestHmrSwitchClient } from './hmr-switch/client'
import { TestTreeShakeServer } from './tree-shake/server'
import { TestTreeShake2 } from './tree-shake2/server'
import { TestClientChunkServer } from './chunk/server'
import { TestTailwind } from './tailwind'
import { TestHmrClientDep2 } from './hmr-client-dep2/client'
Expand Down Expand Up @@ -100,6 +101,7 @@ export function Root(props: { url: URL }) {
<TestImportMetaGlob />
<TestAssetsServer />
<TestTreeShakeServer />
<TestTreeShake2 />
<TestClientChunkServer />
<TestChunk2 />
<TestUseId />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use client'

export function LibClient1() {
return 'lib-client1'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use client'

export function LibClient2() {
return 'lib-client2:__unused_tree_shake2__'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function LibServer1() {
return 'lib-server1'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function LibServer2() {
return 'lib-server2:__unused_tree_shake2__'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './lib-client1'
export * from './lib-client2'
export * from './lib-server1'
export * from './lib-server2'
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { LibClient1, LibServer1 } from './lib'

export function TestTreeShake2() {
return (
<div data-testid="test-tree-shake2">
test-tree-shake2:
<LibClient1 />|<LibServer1 />
</div>
)
}
1 change: 1 addition & 0 deletions packages/plugin-rsc/examples/basic/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export default defineConfig({
if (chunk.type === 'chunk') {
assert(!chunk.code.includes('__unused_client_reference__'))
assert(!chunk.code.includes('__unused_server_export__'))
assert(!chunk.code.includes('__unused_tree_shake2__'))
}
}
},
Expand Down
7 changes: 5 additions & 2 deletions packages/plugin-rsc/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1226,12 +1226,14 @@ function vitePluginUseClient(
// group client reference modules by `clientChunks` option
manager.clientReferenceGroups = {}
for (const meta of Object.values(manager.clientReferenceMetaMap)) {
// no server chunk is associated when the entire "use client" module is tree-shaken
if (!meta.serverChunk) continue
let name =
useClientPluginOptions.clientChunks?.({
id: meta.importId,
normalizedId: manager.toRelativeId(meta.importId),
serverChunk: meta.serverChunk!,
}) ?? meta.serverChunk!
serverChunk: meta.serverChunk,
}) ?? meta.serverChunk
// ensure clean virtual id to avoid interfering with other plugins
name = cleanUrl(name.replaceAll('..', '__'))
const group = (manager.clientReferenceGroups[name] ??= [])
Expand Down Expand Up @@ -1333,6 +1335,7 @@ function vitePluginUseClient(
}
},
generateBundle(_options, bundle) {
if (manager.isScanBuild) return
if (this.environment.name !== serverEnvironmentName) return

// analyze rsc build to inform later client reference building.
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading