#Any equivalent to “use client” for SSR
23 messages · Page 1 of 1 (latest)
In Tanstack Start, all routes and components are client components; you can think of them as if they all have the directive at the top. However, even in client components, you need to add checks before accessing features that are unavailable in an SSR environment (even in next's client components).
Is it because they prerender in server ?
yes!
Thanks for this! I've tried to find an answer for this question in google, documentation, github issues, github discussions, ask AI. Nothing worked and it was here in discord ^_^
What about ClientOnly is not the same ???
what exactly is missing?
Exactly this question. Coming form NextJS and seeing "use client" / "use server" everywhere not having a same thing in tanstack-start was weird while onboarding.
I've checked everything and specially this: https://tanstack.com/start/latest/docs/framework/react/migrate-from-next-js mentions:
Server Actions Functions
tsx
- 'use server'
+ import { createServerFn } from "@tanstack/react-start"
Then following the link in Server Functions I got:
When createServerFn is found in a file, the inner function is checked for a use server directive
If the use server directive is missing, it is added to the top of the function
Finally "use client" I didn't see anything but the previously mentioned "ClientOnly" component that seems different because it's placed in the usage and no the definition of a full component like "use client" does.
In the end maybe we just need a mention (or even an example if suitable alongisde the use server one) of why use client isn't important in tanstack-start architecture.
Not to mention that my code is actually filled with use client directives from shadcn add
I'm unsure if i should change that with another directive/flag. leave it. use ClientOnly, etc.
🙂
probably the docs should state that every component is rendered on the client
did you have a look at https://tanstack.com/start/latest/docs/framework/react/selective-ssr ?
No, I'll check it out. Was saerching for the use client keyword
thanks 🙂
I'm working on an SPA so didn't check any server-side anything jejej
(apart from server functions of course as the SPA mode doc explains No SSR doesn't mean giving up server-side features!)
Oh because the ui packages are expected to work cross app in the future ant it seems a best practice (at least in next) to set "use client" when it makes sense
yeah but if you dont SSR then those directives are not relevant
they are just ignored
makes sense