server-reason-react icon indicating copy to clipboard operation
server-reason-react copied to clipboard

Consolidate `switch%platform`, `browser_only` and `platform`

Open jchavarri opened this issue 1 year ago • 5 comments

There's now a bit confusing situation:

  • browser_only extension
  • switch%platform which include Server and Client branches
  • platform which includes js and native options
  • server-reason-react.browser_ppx uses -js to discard stuff for (modes melange)

We could use React namings and semantics to make things easier for folks to understand.

Maybe we could do something like this?

  • Remove platform as it's covering the same functionality as browser_only
  • Rename browser_only to just client
  • Add server to cover the platform native case
  • Change switch%platform to switch%environment

So to summarize, we'd have:

  • switch%environment with Server and Client branches
  • let%client
  • let%server

Wdyt?


Edited by @davesnx added server-reason-react.browser_ppx` example

jchavarri avatar Nov 28 '24 12:11 jchavarri

let%client and let%server can potentially collide with RSC ppx design thought. Personally, the _only suffix makes the intention clearer, so would rather keep let%client_only and server_only

davesnx avatar Dec 03 '24 19:12 davesnx

let%client and let%server can potentially collide with RSC ppx design thought.

can you elaborate please? Edit: oh, i see, that we can use let%client as the OCaml version of use client and such. But it's not a conflict right? If you use use client then you only want to bundle that code only on the client which is what let%client would do.

Or in another way. Let's say we add let%client_only for this, and let%client for RSC. I guess people will ask "what's the difference between let%client_only and let%client and then we have to explain all implementation specific details, "this is Melange/OCaml boundary", "this is RSC server/client boundary" etc. I'd try to simplify as much as possible.

jchavarri avatar Dec 04 '24 08:12 jchavarri

We totally agree, but we might not add let%client for RSC.

If we can align both, it would be massive, but I'm afraid that isn't the case. Current browser_only discards functions and use client just changes react components.

We could make use client do all the work of browser_only (inside the module), but we can't remove browser_only since functions that aren't react components will also need it. The other interesting bit is that client components need the server implementation as well. which makes use client a bit to do.

davesnx avatar Dec 04 '24 11:12 davesnx

Worth sharing that there's a package called server-only that you import at the toplevel to enforce your bundler to not include those functions as server actions https://www.npmjs.com/package/server-only

And causes those kind of questions: https://www.reddit.com/r/nextjs/comments/18ih6nd/useserver_vs_serveronly/

davesnx avatar Dec 04 '24 18:12 davesnx

we can't remove browser_only since functions that aren't react components will also need it

to clarify, i don't suggest to remove it but rather rename it so there's no different "concepts" going around (e.g. "browser", "client").

jchavarri avatar Dec 05 '24 07:12 jchavarri