Using "use server"; But My Code Is Still Showing On Client. Why?
I'm trying to implement the new "use server"; comment to force parts of my code to run on the server. But it doesn't appear to be working.
Here's an example. I have a AuthService.ts file that uses Supabase Auth. I'm trying to force the "delete user" code to run on the server. Here's the code:
My expectation, is that the code inside of the try block would run on the server.
But if I run
npm run dev
and look at my AuthService.ts file in the Chrome Dev Tools Network tab, this is what I see...
Shouldn't the code below "use server"; in the try block NOT be visible in Chrome?
Am I doing something wrong? Or is this a bug?
Thanks,
Chris4 Replies
you need
"use server"
to be the first line of the function.
"use server"
is only for functions and modules, not for blocksThank you! This would be a great addition to the docs.
it's kinda mentioned in the docs
Haha. I agree. I hope I don’t sound like I’m complaining. I'm just sharing my experience as I try to teach myself SolidStart. I’m a relatively new dev, but I think explicitly saying that “use server”; MUST be the first line of a function or module would add some clarity. It would be even more helpful if the docs showed quick examples of correct and incorrect usage. I’d happily write up and submit what I'm describing if doing so is welcome. I know building SS is a huge undertaking.