You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
docs: Provide examples using tRPC with Next.js app router #5277
Seconding this! It's been hard to find any authoritative sources on TRPC usage with the App Router.
Reacted by Tristan F., Jens Becker, Anton Fedulov, Leonardo E. Dominguez, Matej Šnuderl, Arllo, Antoine, Lovro Žagar, Orlando Groppo, Terry Mun-Andersen and 1 more
Yes, please. I'm going crazy here trying to prefetch an infinite query and I'm not smart enough to figure it out myself. Anyone got some example code for how to get it to work? I've seen some examples where they use an server side helper, call prefetchInfinite, dehydrate the queryclient, then pass it to a HydrationBoundary. But yeah, can't get it to work.
Reacted by Fellipe Utaka, Maryam Khan, Jens Becker, Leonardo E. Dominguez, Dereje, Lovro Žagar, Orlando Groppo and Terry Mun-Andersen
If you're running a separate service for your api layer, it'll likely look quite different. If you are making an SPA, it looks more like how it always has.
It's hard to know what people actually expect and how people want to use trpc for in this new world where React, since RSC and server actions, solves a lot of the things that trpc was created for.
It's hard to know what people actually expect and how people want to use trpc for in this new world where React, since RSC and server actions, solves a lot of the things that trpc was created for.
Here's my take on why I'm still interested in TRPC and why I'm not as hyped about RSC and Server Actions as many.
Warning: so far I've used neither NextJS_with_actions nor TRPC, besides a couple of sandboxes (currently on Zodios), take my conclusions with a grain of salt:
For me, State Control is the most important point, though others matter as well. When doing frontend-dev, I've been building mostly admin panels these days. Since around 2021 NextJS has started to move away from SPA mindset (heavy-interactive), and cater more to heavy-content customers like E-Commerce and image/video platforms. They optimize first load "at all costs" but the first load does not matter nearly as much for interactive apps like games, CMS', etc. Consequent loads, UX performance, dev. experience matters more... and that part was completely ignored (before React 19 that drops stale internals and fixes memoization routine, something good at last). Vercel is free to pursue their business goals, of course, but engineers know that "strongly optimized for X" is inevitably "suboptimal for Y".
Cache invalidation (that NextJS wants me to perform on the server) couples actions to frontend URLs making them barely reusable and/or requires even more wrapping code. Invalidation via tags is rudimentary, the whole thing doesn't stand a comparison with React-Query' rich cache and invalidation functionality. The lack of features on the server and on the client, by contrast to what we used to have with separate API server + e.g. TRPC, is deal-breaking for us. And it can't be easily fixed, IMO, due to their implementation decisions.. Maybe with NextJS v20, who knows 😅
TLDR. If you have most of your logic on the backend... why not use Go/Python instead of NextJS (TypeScript)?
Reacted by Ketill Antoníus Ágústsson, Antoine, Jens Becker, Daniel Gavrilov, Alex / KATT, Ricky and phaed
This issue has been locked because we are very unlikely to see comments on closed issues. If you are running into a similar issue, please create a new issue. Thank you.
Activity
maryamkhan14 commentedon Jan 24, 2024
Seconding this! It's been hard to find any authoritative sources on TRPC usage with the App Router.
ramoneres commentedon Jan 30, 2024
Yes, please. I'm going crazy here trying to prefetch an infinite query and I'm not smart enough to figure it out myself. Anyone got some example code for how to get it to work? I've seen some examples where they use an server side helper, call prefetchInfinite, dehydrate the queryclient, then pass it to a HydrationBoundary. But yeah, can't get it to work.
oeuvars commentedon Feb 1, 2024
Hey @maryamkhan14, you can refer to this video https://www.youtube.com/watch?v=qCLV0Iaq9zU to set up trpc with Next.js App router, also you can go to my repositories and check the Pestile repo which is set up using Next.js app router with Trpc.
Pavan-Rajesh commentedon Feb 5, 2024
This can help you and I will be writing a blog article by today
This is minimalist example and very easy to understand
https://github.com/Pavan-Rajesh/tRPC-Nextjs-App-Router-Minimal.git
Some of the things in the above video are deprecated and some of the docs are also deprecated but vscode helped me ^-^
jeff-computers commentedon Apr 16, 2024
Bump. Also relates to #5625
I can find no explanation anywhere for how to cache trpc endpoints when using the NextJS App Router
iduuck commentedon May 17, 2024
@jeffrey-computers I think Nick Lucas (don't want to ping him here) mentioned on twitter, that the documentation is not being updated until v11 is released: https://x.com/NckLcs/status/1788275302340100304
KATT commentedon May 18, 2024
I think the closest thing to what we want to recommend if you have a monolithic app is to use
@trpc/serveras a slim data layer on top of your backend - you can see that here (in this specific directory) https://github.com/trpc/examples-next-app-dir/tree/main/src/app/postsIf you're running a separate service for your api layer, it'll likely look quite different. If you are making an SPA, it looks more like how it always has.
It's hard to know what people actually expect and how people want to use trpc for in this new world where React, since RSC and server actions, solves a lot of the things that trpc was created for.
ivan-kleshnin commentedon Jun 6, 2024
Here's my take on why I'm still interested in TRPC and why I'm not as hyped about RSC and Server Actions as many.
Warning: so far I've used neither NextJS_with_actions nor TRPC, besides a couple of sandboxes (currently on Zodios), take my conclusions with a grain of salt:
For me, State Control is the most important point, though others matter as well. When doing frontend-dev, I've been building mostly admin panels these days. Since around 2021 NextJS has started to move away from SPA mindset (heavy-interactive), and cater more to heavy-content customers like E-Commerce and image/video platforms. They optimize first load "at all costs" but the first load does not matter nearly as much for interactive apps like games, CMS', etc. Consequent loads, UX performance, dev. experience matters more... and that part was completely ignored (before React 19 that drops stale internals and fixes memoization routine, something good at last). Vercel is free to pursue their business goals, of course, but engineers know that "strongly optimized for X" is inevitably "suboptimal for Y".
Cache invalidation (that NextJS wants me to perform on the server) couples actions to frontend URLs making them barely reusable and/or requires even more wrapping code. Invalidation via
tagsis rudimentary, the whole thing doesn't stand a comparison with React-Query' rich cache and invalidation functionality. The lack of features on the server and on the client, by contrast to what we used to have with separate API server + e.g. TRPC, is deal-breaking for us. And it can't be easily fixed, IMO, due to their implementation decisions.. Maybe with NextJS v20, who knows 😅TLDR. If you have most of your logic on the backend... why not use Go/Python instead of NextJS (TypeScript)?
github-actions commentedon Sep 25, 2024
This issue has been locked because we are very unlikely to see comments on closed issues. If you are running into a similar issue, please create a new issue. Thank you.