Closed hanspagel closed 3 years ago
Workaround (in case someone is landing here):
provider.on('status', (event) => {
if (event.status === 'connected') {
// FIX: Reset the awareness state, before updating a single field
provider.awareness.setLocalState({})
provider.awareness.setLocalStateField('user', { name: 'Hans Pagel', color: 'pink' })
}
})
Hi @hanspagel
Thanks for opening this ticket and also providing a fix! It helped me to narrow down the problem.
The editor bindings shouldn't be able to overwrite your awareness state when you mark yourself as offline (i.e. awareness.setLocalState(null)
). The problem was that in y-websocket, the client marked itself as offline when the connection closes. Instead, we will now keep the awareness state after a disconnect.
I fixed the problem in y-websocket@1.3.8
Oh, that was quick! And that’s definitely a better solution.
I updated to y-websocket@1.3.8 and can confirm it’s fixed. 🙌
Description When clients disconnect from e. g. a y-websocket server, the awareness states are removed. When clients reconnect to the server, and try to set the local state through
setLocalStateField()
that won’t happen, because there is no state to update.As a result the list of connected users (= awareness states) stays empty after losing the connection to the server, even when it’s back online and all clients reconnected successfully.
Reproduction
Expected behavior I’d expect the clients to fetch up all awareness states again after a reconnect.
Environment Information
I’m sending a PR with proposed changes to fix this issue.