Closed julianwachholz closed 3 years ago
Thank you for the report! Fixed in d0d2eb8e12616b69541d960a3753618b176f132b and published to 2.9.1. Will explain details in this https://github.com/robtaussig/react-use-websocket/issues/90.
looks like it not be fixed.
websocketRef
of other shared subscribers should be synchronized after reconnection.
In the event of the server terminating the connection the hook will attempt to reconnect.
Shared connections however fail to update the Ref and will point to the old connection which now has a readyState of CLOSED.
So using
sendMessage
will silently fail and put the message in a queue that is never read.https://github.com/robtaussig/react-use-websocket/blob/5f337b8da99293a43329e2d7ab9c7b5206bce5b4/src/lib/use-websocket.ts#L58
Minimal example: https://codesandbox.io/embed/stoic-leftpad-o0x0g?fontsize=14&hidenavigation=1&theme=dark
For the example to show the error we need to run it locally and kill the server once it's connected and restart it.