Replies: 6 comments 4 replies
-
With this change, the parameter given to - export async function createContext(opts?: trpcNext.CreateNextContextOptions) {
+ export async function createContext(opts: trpcNext.CreateNextContextOptions) { |
Beta Was this translation helpful? Give feedback.
-
You know, you can simply do On my phone, will answer properly later |
Beta Was this translation helpful? Give feedback.
-
The next-hello-world example has ssr enabled if you want a reference |
Beta Was this translation helpful? Give feedback.
-
I know about the I think the default context parameter should be adjusted regardless of that, even when |
Beta Was this translation helpful? Give feedback.
-
I think you have a good point but we'd need a third constant to make it easy to differentiate between them: type CreateNextContextOptions =
| {
type: 'api',
req: NextApiRequest;
res: NextApiResponse;
}
| {
type: 'ssr',
req: IncomingMessage & { cookies: NextApiRequestCookies };
// Altering responses during SSR isn’t a good idea:
res?: never; // Previous thought: `res?: ServerResponse;`
}; The way I've solved this myself when I wanted similar stuff in my Examplecontext fntrpc/examples/next-prisma-todomvc/pages/api/trpc/[trpc].ts Lines 10 to 19 in b0ad15e usagetrpc/examples/next-prisma-todomvc/pages/[filter].tsx Lines 340 to 346 in b0ad15e |
Beta Was this translation helpful? Give feedback.
-
Making When we have a |
Beta Was this translation helpful? Give feedback.
-
I just started using
trpcNext.CreateNextContextOptions
and noticed that it’s typed as follows:While it works great for API requests, the
context
that gets passed togetServerSideProps
only contains a portion of this information – the basis ofNextApiRequest
andNextApiResponse
objects:In order to support SSR better and keep the API context versatile, I propose a context in which only the
req
object is mandatory during SSR, as responses shouldn’t be altered in that case. API functionality is kept intact:Beta Was this translation helpful? Give feedback.
All reactions