Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit "use client" directive for RSC builds #3115

Closed
vicary opened this issue May 10, 2023 · 4 comments
Closed

Emit "use client" directive for RSC builds #3115

vicary opened this issue May 10, 2023 · 4 comments

Comments

@vicary
Copy link

vicary commented May 10, 2023

React Server Components require client-only components to be served with a module-level directive "use client", hook authors are now required to add them to stay forward compatible.

Is there a way to tell esbuild to keep them in the final ESM bundle?

@evanw
Copy link
Owner

evanw commented May 12, 2023

Unknown directives are currently stripped by the minifier. I can change esbuild to preserve them instead. In the meantime, you can use the banner feature to do this.

@evanw evanw closed this as completed in c19689a May 12, 2023
@milovangudelj
Copy link

Sorry to jump in here after all this time but I'll need this soon and just adding a banner to the entire bundle seems a bit excessive. It's been a while since I've used esbuild so I might have forgotten a few things that can circumvent this issue.

Let me know if the situation has changed or not and if there's some magic trickery I can use to keep the directive only for the components that actually need it.

@vicary
Copy link
Author

vicary commented Sep 15, 2023

Esbuild does it's job at the referenced commit, but my experience says that the whole toolchain is usually more than esbuild.

You may need to code split via something like await import(), such that "use client" has a separate file to stay, and make sure subsequent processors (if they exist) do not remove them again.

@clearly-outsane
Copy link

clearly-outsane commented Dec 10, 2023

Did this get released? I've noticed it only keeps the directive in index.ts files and not the chunks and component files. So any nestting of rsc+rcc never will work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants