tRPC + React Query Data Invalidation?

Hey y'all, I'm working with tRPC and React Query and just trying to understand how this works. I have a call that basically sees if the server is online or offline, however, when I disconnect the server I'll get the error eventually on the client, but it won't nullify the query data. Is that normal? Perhaps it just keeps it in the cache -- can I invalidate it to get the proper info? Ex. it'll show online when it's up, but when I turn it off it'll show... error fetching online Not sure why that's the case here.
const query = trpcReact.health.useQuery();

return (
<>
<h1>Dashboard</h1>
{query.isLoading ? 'loading...' : null }
{query.isError ? 'error' : null }
{query.isFetching ? 'fetching' : 'not fetching'}
{query.data != null && query.data.ok ? 'online' : 'offline'}
const query = trpcReact.health.useQuery();

return (
<>
<h1>Dashboard</h1>
{query.isLoading ? 'loading...' : null }
{query.isError ? 'error' : null }
{query.isFetching ? 'fetching' : 'not fetching'}
{query.data != null && query.data.ok ? 'online' : 'offline'}
R
rhh4x0R26d ago
I also tried to switch query.data != undefined, same issue.
S
Sandvich26d ago
Are you as the client turning the server offline or is the client just watching and waiting to see if the server goes offline? If it's the first then you can invalidate the cache yourself if it's the second then the query needs to do polling maybe? or if it's like a websocket connection then you can watch that an when it disconnects invalidate the query Also this seems like a react query question not a tRPC question. Do you want a link to that Discord server?
R
rhh4x0R25d ago
Appreciate it. I had it working on an older version of tRPC but now that you mention it I have new versions of react query too. I’ve got it — I’ll ask there. Thank you.
More Posts
trpc optimistic updates causing data flickerI'm trying to add optimistic updates to a calendar component but when the mutate function is called > Error: Invariant: headers() expects to have requestAsyncStorage, none availableHi, I use trpc v1045.1 in next 14.1 app router. I call it server side and have the following. ```js How do I exclude properties while returning data?I basically need to create a dto's that would exclude properties like access keys etc. while returniDoes anyone have an example of subscriptions implemented in CloudFlare Workers?I'm trying to use subscriptions via WebSocket in CloudFlare Workers, but it's been a real pain so faTRPCClientError: Unable to transform response from serverI am currently encountering this error occasionally in my apps. I am using a Monorepo, which includeUnexpected tokenWorks fine locally, doesn't work when deployed to AWS via sst.dev. Was working last night. RedeployeContext is not being passed correctlyI will include my setup at the end. My problem is that I am using nextauth with database sessions anHow to get the Request Body data of QStashHello everyone. I'm currently working on a client project that involves using trpc with Next.js. We'Preventing uncaught error propagation from server to clientHello guys, is there any way to create default error handler? I want to avoid leaking internal inforThrowing something other than `Unexpected token '<', "<!DOCTYPE "... is not valid JSON`I'm trying to do custom error handling but whatever I throw just ends up being `Unexpected token '<'Create client that is used in every request, without re-creating clientHi all, Consider the following ``` export const createContextInner = async ({ req, res, }: { Using TRPC Server Caller in client side.What's up TRPCer. so i'm currently working in vanilla react app with seperate backend in .NET, in pAnyone has successfully setup a websockets subscription with an input ?Hi guys, here is my environment: *** node v20.11.1 * yarn@4.1.0 * trpc 11.0.0-next-beta.294 * next 1Middleware context changes aren't applied to `responseMeta(opts)` optionsIn our middleware I extend the ctx like this: ```ts const public = t.middleware(async ({ next, ctx Cookie authentication flowHello can i get a bit of a help and explanation please? Im frontend learning backend on trpc, I haveIs It Possible to use methodOverride with createNextApiHandler?I'm trying to build queries for grids and filter and sort object could get very large which is exceeLambda container reuseIn high traffic environments lambda reuses the same container to serve multiple requests. The lambdaTrouble with Vercel and deployment URLHey I've been having a problem with nextjs deploying to vercel. In localhost the calls to the backen