Missing onOpen function in v2
ruggi99 opened this issue · 6 comments
Bug report
Describe the bug
In v1 we had a function called onOpen
, which called a callback whenever the websocket was first established or reconnected.
When I use my app with Supabase I have some disconnections and I listen for reconnection events in order to refetch pobbile stale data. It was so useful.
In V2 it is missing and I've not found any new implementation, nor it is mentioned in docs.
At the actual state for me it's a regression.
Is there a reason for its removal?
I don't think it could create race-conditions or other issues.
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
- Go to '…'
- Click on '…'
- Scroll down to '…'
- See error
Expected behavior
Expect that onOpen
is still present in V2 or at least a valid implementation of the old behaviour
Screenshots
Screenshot not needed I think
System information
Not needed. The implementation is not found in the source code
Additional context
PR that changed this behaviour: #194
@kiwicopple @soedirgo sorry for the ping.
Any thoughts on this?
This is blocking me from upgrading to v2.
Otherwise I'll have to patch the library.
strange that it's missing. @w3b6x9 was this removed?
@ruggi99 we wanted to simplify the exposed API for realtime-js
v2 so we removed the socket's onOpen
. You can achieve the same effect by passing in a callback function to the channel's subscribe
and it will be invoked on initial connection and reconnections:
channel.subscribe((status) => {
if (status === 'SUBSCRIBED') {
// re-fetch data
}
})
Would that be enough to satisfy your existing onOpen
use case?
@w3b6x9
Haven't tried yet but I think it does what I'm looking for.
Also provides a more granular refetching method.
Will test and reopen if something goes wrong
Thanks
@w3b6x9 - should we add this here?
https://supabase.com/docs/reference/javascript/upgrade-guide
@w3b6x9 - should we add this here? https://supabase.com/docs/reference/javascript/upgrade-guide
@kiwicopple good call! will do.