T
TanStack2mo ago
other-emerald

Server function and "internal" functions.

Is there such a thing as internal functions? Something that can only be called from Tanstack start functions. I've just created a system for sending notifications, which will only ever be consumed in server funcitons, so I'm wondering if there's a solution to ensure that sending notifications can only happen from server functions.
3 Replies
genetic-orange
genetic-orange2mo ago
so I'm wondering if there's a solution to ensure that sending notifications can only happen from server functions.
Specifically "server functions" i believe no. There is one for "executeable only on server side" though, serverOnly
import { serverOnly } from '@tanstack/react-start'

const thisCanOnlyBeExecutedOnServerSide = serverOnly(() => {
// ... implementation
})
import { serverOnly } from '@tanstack/react-start'

const thisCanOnlyBeExecutedOnServerSide = serverOnly(() => {
// ... implementation
})
it will throw if called from client side
other-emerald
other-emeraldOP5w ago
Hell yeah, thanks for that! Worked a treat I was looking through the docs for server only, so maybe I just blind on that day
genetic-orange
genetic-orange5w ago
No prob! It, together with clientOnly and createIsomorphicFn are all still undocumented, sadly.

Did you find this page helpful?