t3/env strange behavior on validation

Hi, while using t3 env, I encountered an issue that caused this error message: attempted to access a server-side environment variable on the client. However, the variable in question is consumed by a server action. I’m not sure if this is a bug or if environment variables read within a server action are actually exposed to the client
4 Replies
MAF Evan
MAF Evan4w ago
A bit hard to say without seeing your code, but go ahead and move the server action to a file that only contains server code and see if that fixes it. You need to be particularly careful with closures when you use server actions. Separating server code prevents most gotchas. Theo has a good video that goes over the issue: https://youtu.be/9WvJDor5uvo?si=XXvJdH4ZbV5NV3Eh
Theo - t3․gg
YouTube
I Fixed Next.js Server Actions
Next.js Server Actions have been a long time coming, so happy we can finally talk about them! Check out zact: https://github.com/pingdotgg/zact ALL MY VIDEOS ARE POSTED EARLY ON PATREON https://www.patreon.com/t3dotgg Everything else (Twitch, Twitter, Discord & my blog): https://t3.gg/links S/O Ph4seOne for the awesome edit 🙏
younes
younesOP4w ago
Thanks for the response. My server action is properly placed in a separate file with the "use server" directive at the top, but it's still the same issue:/
younes
younesOP4w ago
Gist
action.ts
GitHub Gist: instantly share code, notes, and snippets.
MAF Evan
MAF Evan4w ago
You could try adding “use server” to the top of http-client.ts? Doesn’t look to me like you’re actually leaking anything, might be that t3 env is rather aggressively telling you that you could accidentally do so?

Did you find this page helpful?