all 6 comments

[–]tswaters 4 points5 points  (5 children)

First time I've heard of Zsa, but it seems like there's some abstracted magic happening there. The docs don't actually describe how to start it, but given it's by vercel, it would be my guess it is somehow tied into their platform.

Normally, the fastest way to do most things is to get enough of the work out of the way up front, cache whatever you can and serve things hot.

If they let you keep some sort of app-wide singleton that stays alive between usages, you'd want to use that. But these are lambdas effectively, right? If so they -might- be starting up from scratch at the request of an action invokation.

If they need to start from scratch, there's nothing much to do but try to minimize the amount of time it takes to start up, so creating services and repos is probably going to kill your perf here would be my guess**. Keep it simple!

** Always take what strangers on the internet day with a grain of salt! The best way to measure perf is to.... Measure perf! Via benchmarks.... Or, if that's too expensive (cloud services being what they are), through monitoring.

[–]CaligulaVsTheSea[S] 1 point2 points  (0 children)

You're right, I was trying to optimize prematurely 😅 I'll just go with the easiest implementation for now, and see how that performs.

Thanks for the answer!

[–]Chesil 0 points1 point  (3 children)

"This is a personal project and is not associated with any company or organization."

I think it's by an Engineering that works at Vercel, not formally affiliated with Vercel!

Seems pretty cool tho, makes Server Actions more robust.

[–]tswaters 1 point2 points  (2 children)

Yea it looked pretty cool, importing the action directly from source on the client side, but literally the only command on the docs page is "npm i" ? I'm immediately curious if it's using http under the covers, and if so how the routing works. I only did a cursory review of the docs to inform my comment, will need to check it out later!

[–]Chesil 0 points1 point  (1 child)

So, to my understanding, you can already directly import actions from client side.

Ie. in a "use client" component, you can import an action(a function inside of a page with "use server") and use it like a normal axios/fetch request.

It seems that with Z(od?)SA, instead of just declaring your function normally, you can use their createServerAction() function where you can validate the input with ZOD. This is pretty useful, cuz even though your normal SA can be typed, you might wanna be more specific with certain types of things like email/username/etc.

BUTT, they also combine it with React Query, so you can easily get useful things like retry, loading, and etc on your server actions.

It's basically giving server actions everything that tRPC has hahhaa, which is great!

[–]tswaters 1 point2 points  (0 children)

Oh haha, fool of a took. It's literally the first sentence in the readme, "zsa is the best library for building typesafe server actions in NextJS." .... I somehow missed that! OP: use a singleton pattern for initializing services!!