Does the entire file of a 'use client' component get bundled, regardless if all exports are used or not? #82843
Unanswered
jfarris587
asked this question in
Help
Replies: 1 comment 2 replies
-
Have you checked if this is also the case with Turbopack? |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
I’ve noticed that when a file contains the "use client" directive, tree-shaking seems to stop working for its exports.
Suppose I have a client component file with multiple exports:
Even if I only import one export in a page or another component:
the entire module, including ButtonSecondary, gets bundled into the client-side JS.
From my understanding, "use client" marks the file as a client boundary, so Next.js can’t safely shake unused exports.
I want to verify if this behavior is intentional or if there’s a recommended pattern for keeping tree-shaking working while still using client components. If so, then it seems the recomended path is:
Additional information
No response
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions