Comments (5)
I know about the { ssr: true }
option, but that relies upon getInitialProps
, which breaks SSG for static pages. I wouldn’t like to use that option due to this.
I think the default context parameter should be adjusted regardless of that, even when { ssr: true }
is specified. I proposed not to forward res
during SSR, but always forward req
so that cookies can be read (e.g. for auth)
from trpc.
With this change, the parameter given to createContext
should always be required:
- export async function createContext(opts?: trpcNext.CreateNextContextOptions) {
+ export async function createContext(opts: trpcNext.CreateNextContextOptions) {
from trpc.
You know, you can simply do ssr: true
in the top level HOC to enable ssr, you don't need to do any manual ssr stuff unless you specifically want ssg
On my phone, will answer properly later
from trpc.
The next-hello-world example has ssr enabled if you want a reference
from trpc.
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 getStaticProps
-fns is to make opts optional so I can simply call my createContext
from the function.
Example
context fn
trpc/examples/next-prisma-todomvc/pages/api/trpc/[trpc].ts
Lines 10 to 19 in b0ad15e
usage
trpc/examples/next-prisma-todomvc/pages/[filter].tsx
Lines 340 to 346 in b0ad15e
from trpc.
Related Issues (20)
- feat: (customizable) query key prefix HOT 2
- bug: HOT 2
- docs: @trpc/[email protected] uses @tanstack/[email protected] whereas in documentation of trpc installation in nextjs it installs @tanstack/[email protected] , it is conflict error HOT 6
- feat: Automatic query invalidations HOT 5
- bug: observable automatically calls cleanup function with bun HOT 4
- docs: Provide examples using tRPC with Next.js app router HOT 4
- ## Provide environment information HOT 3
- bug: Unable to call createServerSideHelpers on RSC - NextJS 14 App Router HOT 2
- bug: TRPC Calls from RSC cause Next to throw dynamic server error. HOT 3
- feat(v11): make it easier to extend tRPC HOT 1
- docs: Valibot URL not working in Quickstart HOT 2
- feat: Use latest version of pnpm HOT 1
- bug: Context & InnerContext sample not working HOT 4
- feat: return `Promise` in `.listen()` HOT 8
- docs: Incorrect Order of Version List in Dropdown HOT 6
- bug: `useSuspenseQuery`/`useQuery` always requires the input to be defined even if it's optional HOT 1
- bug: `router.path.revalidate()` returns `undefined` instead of revalidation result in next app directory. HOT 3
- fix : Missing 'express' import in adapters/express.md documentationdocs: HOT 1
- bug(next): bundle size increase between `10.44.1` -> `10.45.0` HOT 8
- bug: useMutation hook error with latest @tanstack/react-query version HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from trpc.