Replies: 1 comment
-
soon! ![]() |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
At the moment, server functions suffer the same problem as loaders in Remix and Next.js: Input and output must be JSON-serializable.
While you can manually do the encoding on each side (before calling the server function and before returning something from the server function), and do the decoding within the server function and on the client after calling it, this is anything but ideal.
I'd suggest to allow configuring codecs, both for the input as well as the output. A codec should have a form like this:
By using a type like this, it would allow using e.g. Zod (>=4.1.0) codecs for this: https://zod.dev/codecs
Beside being more ergonomic, this would also allow for optimizations; e.g. on server side calls the de- and encoding can be completely skipped, while it would only be used for hydration and client side calls.
Usage could look something like this:
Another advantage of this is that the input codec not only takes care of encoding on the client side, but also decode and validates on the input side. So this would eliminate the need for a separate validator. Additionally the output codec would ensure that the user returns the correct type from handler (enforced by TypeScript).
Beta Was this translation helpful? Give feedback.
All reactions