developit / microbundle

📦 Zero-configuration bundler for tiny modules.
https://npm.im/microbundle
MIT License
8.05k stars 362 forks source link

Build for React Server Components #1060

Closed tats-u closed 1 year ago

tats-u commented 1 year ago

https://github.com/reactjs/rfcs/blob/main/text/0227-server-module-conventions.md#react-server-conditional-exports

React Server Components seem to require independent source (e.g. useState is not allowed) and requires "react-servers" in "exports" in package.json.

Microbundle doesn't seem to support this currently.

rschristian commented 1 year ago

You can simply map "react-servers" to Microbundle's (existing) output, I don't think we should do anything different for arbitrary export conditions, personally.

Edit:

React Server Components seem to require independent source (e.g. useState is not allowed)

Not quite sure why you brought this up though, what do you expect Microbundle to do about this? Seems to be a user-code issue?

tats-u commented 1 year ago

Not quite sure why you brought this up though, what do you expect Microbundle to do about this? Seems to be a user-code issue?

The project I want to add the RSC support uses this project. It uses useState as of now.

rschristian commented 1 year ago

Then remove the useState?

tats-u commented 1 year ago

@rschristian It's bad. It does not render anything at first, but generates what should be rendered in useEffect and then rewrites the content. This is ideal in the client side. And it's not my project. As far as your response, this doesn't seem to be the use case you're envisioning.

rschristian commented 1 year ago

It's bad. It does not render anything at first, but generates what should be rendered in useEffect and then rewrites the content. This is ideal in the client side.

I don't follow -- what's bad?

Microbundle is intended to be a pretty generic bundler for tiny modules, it doesn't make much sense (IMO) to integrate a bunch of RSC-specific tooling. If RSCs don't support hooks, then that's something you need to handle on the input side or use a Babel plugin to strip out. Same goes for custom export conditions, you'll need to make sure your conditions match the files output by Microbundle as it won't take those paths into consideration itself.

I don't think there's anything actionable here for Microbundle. These are both items that should be addressed on the module's side of things.

tats-u commented 1 year ago

I don't follow -- what's bad?

From the client-side perspective, useEffect and useState are necessary, so we have to split the entrypoints.

Microbundle seems not to be for the project (that needs multiple entrypoints) now. Thanks.

rschristian commented 1 year ago

Indeed, but we're not the ones who wrote the RSC spec, not sure what you'd like us to do about it.

Again, a Babel plugin to strip out hooks could be another approach (then you'd just run Microbundle twice, once for the client component output and another time for the server) though I'm not sure if anyone's made that. Might be worth looking at other projects to see how they handle it.

I'll close this out as I don't think there's anything for us to address but if you do have any Microbundle-specific questions in the future feel free to ask.