t3 tRPC - CTX is undefined
Hey all. Finally checking t3 for the first time.
Question.
I was trying to add to the latest post query so that the latest post will be from the current user not all users.
<LatestPost> has a call to getLatest
const [latestPost] = api.post.getLatest.useSuspenseQuery();
Which is called serverside first. I am confused why, for the first serverside call, ctx in trpc is null.
To be fair this is fixed when
void api.post.getLatest.prefetch();
is called in page.tsx
But I do not understand why I have to prefetch getLatest
for this to work?
Apologies if this is not the place to ask this or my question does not make sense.3 Replies
did you end up figuring it out @Simon Verhoeven ?
Hey @Hobbs no. I think I am experiencing something similar to this https://discord.com/channels/966627436387266600/988912020558602331/1270507000371085382
CTX is null for the first call.
For now I am just either
- Using server components to fetch the data (as this issue happens only on
use client
components)
- Pre fetching in a parent server component seems to fix it
But yeh I would still like to understand the issue here, why the sever render on a use client
component has ctx undefinedI think you may be looking for using something like the
privateProcedure
instead of the publiceProcedure