6 ms·
It's funny, but all you see here and on Twitter are cheap shot one liners, many of these people have never even used Next.js. I find server actions combined wi
by bottlepalm 3y ago
It's funny, but all you see here and on Twitter are cheap shot one liners, many of these people have never even used Next.js.
I find server actions combined with RSC to be incredibly useful and powerful. Easily define and call a type safe function from client to server with zero overhead. No API boilerplate, fetch, tRPC anything.. You just define a function and call it, very nice. Type safety, code completion, refactoring works across client/server, all that.
Of course the examples of server side code in client side function handlers are just that, examples, not the suggested way to use server actions. You can write super hacky 'bad' code in every language. Server actions are best defined in their own file of course.
Not sure why it's being compared to PHP so hard as PHP is a backend only SSR framework, while Next seamlessly transfers the components/code/state to the client so you can continue re-rendering with the same framework and language client side as you used server side for SSR. PHP could never do that.
The closest thing to server actions in PHP is Livewire, which was never a standard part of PHP and not unique to PHP either. Most PHP apps just use normal JS libraries for interfacing with the server.
- rpmisms 3y agoThey're really cool, and act like the best parts of PHP. I actually miss the simply powerful aspect of the paradigm.
- bottlepalm 3y agoWhat part of php? php doesnt render on the client, and most php apps except for livewire don't integrate call backs to the server.
- rpmisms 3y ago"act like" here meaning DX, not actual behavior. Magical actions within UI code.
- bottlepalm 3y agoI mean doesn’t asp, python, ruby, JavaScript, etc.. all have templating languages you can do fun things in?
- 0natcer 3y agoi just wanna add here on a serious note that i also see a use cases for "server actions", but i do not primarily write next.js or react so i didn't have an opportunity to try them out yet. I think it's important to know what you would use them for. I don't think core business logic should be there, but I see why you would use them for f.e. signing something that would require a secret you don't want to have on the client side. I do however think that it's not a good idea to show the inline code example in a presentation. fortunately none of those examples exist in the documentation. having a seperate file with server actions that can be imported is a good way to handle it i think.
- bottlepalm 3y agoI could take this php example or raw sql code and put it in the body of an API call from the client. Are API calls bad now? Same thing. A misunderstood example.
- stevebmark 3y agoI'm entertained by the trolling, it reminds me of when React first launched, to see who was yelling the loudest about React violating separations of concerns, and totally missing the point, just jumping on the bandwagon. It feels like a similar thing this time around. It's fun to keep tabs on who misses the point.
- lyu07282 3y ago> Not sure why it's being compared to PHP probably just because PHP is now recognized widely as fundamentally bad design. Its just that many people who came late to the party never really knew why, so they think to themselves, no this is actually great "no API boilerplate, fetch, tRPC anything.. You just define a function and call it, very nice.". And so the cycle continues...
- DoesntMatter22 3y agoWhat do you think is fundamentally bad about PHP exactly? It powers a large percentage of the web and does it quite well.
- coding123 3y agoI installed wp with a theme a few years ago and the box was turned into a zombie file dump. Modern php is still not there.
- muglug 3y ago“I installed some third-party PHP software and didn’t turn on auto-updates for that software, and then my server got hacked” is a hit on your server admin skills, not PHP.
- coding123 3y agoThe attack vector was directly through php. Everything was upgraded to the latest. It was the theme that was hacked. How that is related to admin skills makes no sense.
- DoesntMatter22 3y agoIf it was the theme that was hacked then it wasn't PHP it was the design of wordpress and the theme specifically. Almost all hacks of wordpress are not due to workpress itself but due to the themes and extentions. If it was written in another language you'd have the same problems with the same architecture. Wordpress gets exploited because it's popular, not because it's written in PHP
- spion 3y ago> You just define a function and call it, very nice. What do you do when you change the action API (arguments / return type) and deploy? What happens with browsers still having the old code that assumes the old contract?
- bottlepalm 3y agoPretty much the same as dealing with traditional API versioning. You can version the functions themselves, or put a version in they payload and return an error telling the user to refresh.
- spion 3y agoHow do you version the functions? How does the server determine which function to call? Does it use the name of the function, or its source code file, or something else? If I rename the old version and call it `actionOld` while the new version is `action` will it know how to call the old one, or do I need to do the opposite (call it `actionNew`)? What if I move the old one to a different file?
- bottlepalm 3y agoYou can use a v1 folder for your v1 functions. The server identifies functions by path and name of the action. Similar to a url. So like a url if you want a new one, you'd create actionNew, and if you move the location of the function it would break old versions without a redirect.
- spion 3y agoIs this documented anywhere?
- bottlepalm 3y agoNot sure. I just read the code. https://github.com/vercel/next.js/blob/ffdfd33251165d8b2f092568c8e4e5f08c71a636/packages/next/src/build/webpack/loaders/utils.ts#L48 https://github.com/vercel/next.js/blob/ffdfd33251165d8b2f092...
- deleted 3y ago[deleted]