Caching and invalidation in t3-stack with app router and trpc
Hi guys, can someone explain what is the correct way to do invalidation with app router and trpc? Is there even such a way? I am talking about the use case where I have a server component fetching data with trpc query and a client component firing a mutation which make the data from the previous render obsolete
6 Replies
in your react application, after you call your mutation you can do something like:
In my t3 app with app router when I invalidate a api call it makes my page refresh , this is happening only in dev and not in production 😅 .Any idea ?
This is the link to the code repo : https://github.com/sohan9819/devloop
In this I am revalidating the post.getAll whenever a new post is created and it refreshes the entire app when a new post is created.
GitHub
GitHub - sohan9819/devloop: A platform to connect developers
A platform to connect developers. Contribute to sohan9819/devloop development by creating an account on GitHub.
Dude, it’s just regular client side fetching with trpc, that’s not what my question was about
Basically using trpc with RSC is a mess and should be avoided IMHO (at least in the current state of things)
i dont think u can invalidate a server query, that should only be run once on the server. You can try passing the data from the server query to your client component, => create another query via the client api and useQuery ,then use that data passed from the server (in the client comp props) as the initalData prop in the useQuery
This works perfectly! But is this the "correct" way to go? This does not seem like a niche Problem.
I saw it in a Jack Herrington video that came out not long ago about using trpc in app router