Switch from "use server"
back to using server$()
#1880
samualtnorman
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
After having used
"use server"
in production on PetScanner's web app for 6 months, we have now switched back to usingserver$()
. We didn't downgrade back to SolidStart 0.3, I instead developed a babel plugin:Babel plugin code
It transforms code like:
into
And then leaves it up to SolidStart's transforms to handle the
"use server"
from there.The reason we have gone back to using
server$()
is that"use server"
is less composable.SolidStart by default leaks server errors that occur in a server function to the client. We have a wrapper function that is used like so:
This is not so easy with
"use server"
.By default in SolidStart, server function input is not to be trusted so we can mix and match an input validator like so:
I'm not saying this is impossible with
"use server"
, just that"use server"
is a downgrade compared toserver$()
.None of these code samples are taken directly from our repository. The given babel plugin is a slightly simplified version of the real one we use, and the other code samples are contrived examples.
Beta Was this translation helpful? Give feedback.
All reactions