The context here (as I understand it) is that Next.js, a popular React-like framework that allows (in a way) coding both the server and browser portions of a web app in one codebase, such that each portion is extracted at runtime and automatically wired up via API calls. This is a simplification but it's how you can think of it.
They've now introduced an even tighter way of introducing server code into what are otherwise frontend React components by piggie backing off the old "use strict" directive syntax, called "use server", allowing you to interleave - directly and inline - the client and browser code.
Many a meme have been created, half-jokingly comparing it to PHP, ranging from the supportive jest, to the very seriously critical, as one would expect the internet to do.
Some of those memes have been in the form of "use ___", such as "use binary", "use php", etc.
I don't use frontend frameworks much these days so maybe someone can correct me on some of this, but hopefully this helps explain it a bit.
https://nextjs.org/docs/app/api-reference/functions/server-a...
These conditional checks on server state exist because they didn’t create the shared environment between web server and web browser at deep enough of a level.
The key is to replicate the server-side pattern of “user actions cause HTTP request”. That is, you make a version of express that runs in the browser. Then you make parallel middleware that runs in both the browser and the server. Then you make your React components fire off mock HTTP requests that are handled by the browser express router.
So you write the same route handlers and components for the browser and server to run but then you write environment specific middleware.
Browser middleware:
https://github.com/williamcotton/williamcotton.com/tree/mast...
Server middleware:
https://github.com/williamcotton/williamcotton.com/tree/mast...
I’ve expanded beyond express in the above application to add controllers, a routes file, and views, all code that has no conditionals and runs in both the browser and server environment.
What NextJS demoed is poorly conceived. There’s no need to autogenerate a link to an API.
Instead, your frontend middleware has req.update() defined to make an API request and the server middleware has req.update() defined to make the SQL update. GraphQL pairs well with this approach, but so does something like Graphiti/Spraypaint for a more traditional ORM-like model.
And there you go, sane server and client side rendering.
https://twitter.com/dan_abramov/status/1717648341234778376
The html for the button gets SSR and sent to the client. The button click handler is an RPC that runs the actual sql statement on the server.
Well, it takes very little knowledge to know this isn't a good design paradigm.
https://samgen.vercel.app/GYVwdgxgLglg9mABAITnA1gWwIYCd0AUA3...
You just don't use javascript enough in your life.