Trace export usage through client component proxies (#98621)
## Summary Turbopack previously widened export usage to every export when a Server Component crossed a client-component proxy. As a result, importing one named export from a `use client` module retained unrelated implementations in both browser and SSR bundles. This extends Turbopack's import annotations with a generic export-usage passthrough. The server transform for `use client` modules marks its generated namespace import as passthrough, so the ordinary binding-usage fixed point carries the Server Component's used export set into `EcmascriptClientReferenceModule`. Its client-reference edges use the same signal to forward that set to browser and SSR targets. Side-effect-only evaluation references retain their evaluation semantics instead of inheriting the annotation. The forwarded names remain namespace-observable because React Flight resolves client references by their original export names, so unused exports can be removed without changing the protocol-visible identity. An importer whose usage is `All` still forwards `All`. The client-component tree-shaking test now checks that unused markers are absent from every browser chunk and verifies the same behavior in Turbopack SSR chunks. ## Verification - `cargo fmt --all -- --check` - `cargo check -p next-core` - `cargo test -p turbopack-core module_graph::binding_usage_info::tests --lib` - `pnpm build-all` - `pnpm test-start-turbo test/production/app-dir/client-components-tree-shaking/index.test.ts` - `pnpm test-start-webpack test/production/app-dir/client-components-tree-shaking/index.test.ts` <!-- NEXT_JS_LLM --> <!-- fleet 10716dab-2d36-4687-94ae-cd7bdfeac985 --> --------- Co-authored-by:vercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com> Co-authored-by:
Tobias Koppers <1365881+sokra@users.noreply.github.com>
Showing
Please
register
or
sign in
to comment