MichaelM
Convex Community9mo ago
1 reply
Michael

Error when unsubscribing from browser.ConvexClient query

The error is: Cannot read properties of undefined (reading 'numSubscribers'), here in convex/browser.

We are using the browser.ConvexClient in a Hono app to listen to updates from Convex, as outlined below. While calling unsubscribe too many times, an error is triggered inside the Convex code.

How can I test if it's safe to call unsubscribe? Since unsubscribe returns void, I think it would be better if it just doesn't do anything rather than produce an error if I unsubscribe too often.

const unsubscribe = client.onUpdate(api.queries.myquery, { id: myid }, updateHandler, errorHandler);
...
unsubscribe?.()
unsubscribe?.()
GitHub
TypeScript/JavaScript client library for Convex. Contribute to get-convex/convex-js development by creating an account on GitHub.
convex-js/src/browser/sync/local_state.ts at f7d0bdb241f0b5e911887f...
Was this page helpful?