subscribe to query changes on the client
hi!
I need to watch for changes on a query on the front. The code for the watcher is also on the front.
I'm using this code on the watcher:
const client = new ConvexReactClient('my instanmce url on convex', {}); const watch = client.watchQuery(api.myquery, {id: my id string as id<"mytable">}); watch.onUpdate(() => { setOptimistic([]) });I need to watch the query because i need to simulate optimistic mutations ( i can't use optimistic updates directly because those updates are made by scheduled mutations), so i add those updates in an array and render them, i empty the array once i know the changes are performed (hence the query being watched). Anyways... the code is working, a bit ugly, but working, but it also triggers infinite errors in the console:
Attempting reconnect in 17192.633050199267ms web_socket_manager.js:64 WebSocket error: undefined web_socket_manager.js:86 WebSocket closed with code 1006 web_socket_manager.js:134 Attempting reconnect in 9087.685573583634msand it degrades the performance and makes me nervous... Any tip/recommendation? (best way to simulate optimistic updates, or get the ugly errors go away?) Much appreciated!
2 Replies
Hey @Rodrigo-R, that is very unexpected, could you put together a repo that reproduces the issue?
let me check, pretty busy but i'll try. but the issue is basically just putting the code as it is.