SolidStart - Server Only
I see a way to ensure functions only run on a server, but what about modules that declare classes? I guess that I need to use a factory function instead?
https://docs.solidjs.com/solid-start/reference/server/use-server
6 Replies
If you only import those modules in places that are
use server
then they won't reach the client
If you want to ensure a module isn't imported on the client add
yeah, but what if someone mistakenly uses a module that i don't want to ever reach the client? how do i say to the next developer or to myself "Hey don't use this on the client side!"
better than nothing i guess. the lines are a little blurred here. it makes me queezy.
Also to be a bit more precise
use server
shouldn't just be used everywhere that you want to keep something server-only. It should only be used for marking functions that you want to expose to the client via RPC
fwiw react's equivalent is to import a server-only
npm package that has basically that same code inside of iti'm used to making separate web services, but i like the convenience of solidstart. afik the only reason to leverage "use server" is for convenience. is there another?
Only other thing i can think of is that they support Single Flight Mutations
It is mostly about convenience - being able to define server things inline and having serialization of a bunch of types dealt with for you
FWIW I was able to use a a factory function in combination with "use server"
like: