Why does Convex spam function calls?
It's entirely possible I'm using it wrong, but it's spamming my calls without a care in the world.
It does this every half a second without seemingly any reason to do it, the data has not changed, nor am I interacting with the APP.

54 Replies
Chances are you've got state updating somewhere that's causing those to reload more often than they need to.
Can you share more of the app code relevant to where this is happening?
Let's start with auth, because this is using custom JWT
Second, relating to the first snippet I sent, this is the only way I'm using it
or
I can't see how this would trigger an infinite loop
Here is a log visualization
and this is sync ws
May I ask, where are you calling the functions from? the TextDisplay component? or is the compoonent wrapped outside of it?
Calling it from the main default exported component
This component is always visible
funny thing is it's doing this for every component that is currently visible and has a useQuery
I recommend looking into passing "skip" in the variables, so instead of
{}
use something like: hasToLoad ? undefined:"skip"
into the useQuery,
but, I'm guessing that you need to look into the top level compoennt where you're calling this functions from, on each render, there will be a function call
You shouldn't pass empty objects into the query call
if no object is expected pass undefined
Doing
useQuery(api.game.getLastRound)
or
useQuery(api.game.getLastRound, undefined)
doesn't have any effect
doing
useQuery(api.game.getLastRound, "skip")
works, but it defeats the purpose of use querybut to be fair, the caching works perfectly haha
caching works definetely
im just worried about the function call number
no no, this is not what I recommended
this is simply skipping the function call entirely
usefull in case I want to enable it after some condition
what other context can I provide?
I'm using Next 15.5.2, don't know if that matters or not
mutations seem to be fine, queries are spamming every 300 millisesconds or so
or is that regular behaviour?
https://docs.convex.dev/client/react#skipping-queries
could you elaborate a bit?
does it still happen if you comment out
<EnsureUserOnAuth />
that's also a good point
i don't know what that's doing, but... i sense something...
yep it's still going at it
even with that commented out
i'm sensing it's the auth as well, but I just can't understand what
cream, do me a favour, can you share the code of where the component where the query gets called?
like parent of the child node
so
page.tsx (parent) -> BounceControl.tsx (child w/ the useQuery)
you need the page.tsx?
the bouncecontrol is where it gets called? can you share the part of where that component gets called?
Discord doesn't let me send the whole thing, but here is the return of page.tsx
that holds BounceControl
where do you change active tab?
and this is the top of BounceControl
where does the variable activeTab get changed?
in here
however, this is unseen for my desktop version
there's a lot going on here. what can you comment out to make it stop happening?
give me a min to read
removed everything
still hammering
could you console log the activeTab variable, in the component MobileMenu, and in the Page with a useEffect?
if it gets changed so many times, that's where you need to look
on every change, the component re-renders, and so do the function calls
I see, is there any extension I can use to see these react rerenders?
uhhh you can use the default dev tools
the rendering tab, but with a console log and a useEffect it does the same thing
HAHAHA, give me a moment to take a better screenshot

rn im down to just this, and it still hammers away
which is the rendering tab?
this is showing auth looping, right? that would constantly invalidate your queries
exactly
but why is auth looping
because i've commented out everything else, and it still hammers
so it may be the auth
here are my two files related to auth
convexprovider.tsx
and inside convex folder
i dunno i just use clerk 🤪
not an option sadly
I've lost track of everything. sorry I won't be able to help much in here 😅
Ok, here to help with more info
It's definetely the Auth
as I've removed it completely
and now it finally works as it should
but I need my auth
wow, it's refreshing to see it behave normally
Yeah I don't have much information, but can try to run the code later today,
I'd look into the useEffect
that is commented out
comment one thing after the other until you figure what's invalidiating it
do you still see the logs if you remove it?
id never heard of Privy, and ive never dug into auth. but your problem is there
me too!
ive never even used convex auth haha...
you might want to check the custom convex-auth thingy for this,
https://docs.convex.dev/auth/advanced/custom-auth
"update the provider code to make a custom provider for your case"
oh yes it's spamming like crazy so it's not the use effect
cause I can see its memoised in the docs but not in your case
but rather this snippet
try memoising the return statement to the top
did that
stil nothing changed
I'll need to run it to debug
no worries
I've managed to fix it
needs to look like this
Sweet!