Is it possible that adding a second
Is it possible that adding a second subscription to a query with the same parameters won't get an immediate callback with the last value?
14 Replies
If I make multiple subscriptions at once, they all get updated. Subsequent subscriptions don't get updated unless the document changes.
If I add a random unused cache busting string as a parameter, it seems to work as intended
yep
well, do you mean, they don't even get the current value?
the subsequent subs with the same parameters?
This depends on the API you're using, e.g.
will not run immediately, it will run once a query update is received.
That might be pretty quick (if this is a new query, the client will tell the server to start a subscription on it and will get a value in ~the time it takes for a network roundtrip) but it might be a long time if the client already had a subscription on this query.
Is this the kind of thing you're talking about? if so you can synchronously check for the current result by checking
watch.localQueryResult()
to see if it returns something other than undefined
If you're using a different API, the same concepts may apply — watchQuery
is a ConvexReactClient API, the InternalConvexClient equivalent is client.localQueryResult(query, ...args)
for synchronously checking for the current value, only present if there a subscription on this (query, args) combo already.ah forgot, @magicseth is not using react, eh?
b/c
useQuery
should handle this for you
from convex/reactmy vue wrapper is calling this:
If I have already subscribed, I see the ref counter increase
but I don't have a cache of values at my layer
addSub
isn't a Convex function, I think that's yours too? Is it wrapping the InternalConvexClient? I think in there I'd add the setter to your callback list, then call it manually if client.localQueryResult(name, fullArgs)
returns something other than undefined
const { queryToken, unsubscribe } = this.client.subscribe(queryPath, args);
That is what my addSub function is
so I should add the localQueryResult immediately
okay
yeah something like
that seems to have done the trick, still some flickering but it is getting updated!
Just a shot in the dark, it's possible that batching your updates could fix the flicker https://www.how-to-vue.com/vue/reactivity/batch-update.html
but that's really a guess, if you want to donate your Vue client I will take a look and try to fix this and post a https://stack.convex.dev article on it
It's mostly based on Jamie's Solid convex
with just a little ref() magic
awesome, I'll give this a shot when my boss isn't looking 😛
thanks!