laurence
laurence2d ago

TRPC not writing to QueryCache?

Hi all, I've been using TRPC in a production site for over a year now. I recently have made some additions to this site that required cache invalidations, but for whatever reason I couldn't get them working. Troubleshooting the reason led me to discover that it appears the querycache my trpc instance is using is just always empty. (Empty cache = nothing to invalidate?). I built the app using T3 and when I migrated to app router I built a new T3 app and used it as a reference. I've been looking at the differences between a fresh T3 creation and my app and I just can't find anything that could be the culprit. I've tried saving the queryclient to the window and it looks fine except it’s got an empty cache.
4 Replies
laurence
laurenceOP2d ago
What I see in devtools. TRPC calls shown in the console, but nothing in tanstack query devtools
No description
laurence
laurenceOP2d ago
Gist
TRPC QueryClient Empty ( "_" == "/" file name underscores are folde...
TRPC QueryClient Empty ( "_" == "/" file name underscores are folder path) - server_api_trpc.ts
laurence
laurenceOP7h ago
Are there other files I should be looking at for this? Any other things I can log or inspect? package.json
"@tanstack/react-query": "^5.66.0",
"@tanstack/react-query-devtools": "^5.66.9",
"@trpc/client": "11.0.0-rc.748",
"@trpc/next": "11.0.0-rc.748",
"@trpc/react-query": "11.0.0-rc.748",
"@trpc/server": "11.0.0-rc.748",
"@tanstack/react-query": "^5.66.0",
"@tanstack/react-query-devtools": "^5.66.9",
"@trpc/client": "11.0.0-rc.748",
"@trpc/next": "11.0.0-rc.748",
"@trpc/react-query": "11.0.0-rc.748",
"@trpc/server": "11.0.0-rc.748",
I just realized it's probably because I'm calling all trpc endpoints server side without prefetch. So they're not in the cache. Will try switching to prefetch with hydration boundary and report back
laurence
laurenceOP7h ago
That was the issue! This ended up being quite confusing. It might be nice to have a note in the invalidate / refetch docs (I suppose within react query docs) that calls this out.
No description

Did you find this page helpful?