Consolidate `switch%platform`, `browser_only` and `platform`
There's now a bit confusing situation:
browser_onlyextensionswitch%platformwhich includeServerandClientbranchesplatformwhich includesjsandnativeoptionsserver-reason-react.browser_ppxuses-jsto 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
platformas it's covering the same functionality asbrowser_only - Rename
browser_onlyto justclient - Add
serverto cover theplatform nativecase - Change
switch%platformtoswitch%environment
So to summarize, we'd have:
switch%environmentwithServerandClientbrancheslet%clientlet%server
Wdyt?
Edited by @davesnx added server-reason-react.browser_ppx` example
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
let%clientandlet%servercan 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.
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.
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/
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").