You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using next-ws's built in WebSocketProvider component and useWebSocket hook, in order to establish and reference a websocket connection. I have come to find that when inspecting dev tools i can see that 2 websocket connections are established when the WebSocketProvider component is accessed. This is understandable as I am in development and as such react strictmode is enabled - however by inspecting chrome dev tools' network > messages tab I can see that both connections remain open as they continue to receive data from my server. \
This is not in itself breaking for me, as my server can handle a user having multiple open socket connections, although I do wonder if it is intentional and perhaps not the case that only one connection should remain open and instead some useEffect clean-up callback is missing somewhere in next-ws?
The breaking issue that I am facing is that seemingly only when a certain client component of mine is loaded, does one of these two socket connections unexpectedly close with code 1005 very shortly after opening.
This is what I typically see when in my server log's when I load the page (and WebSocketProvider establishes websocket connections)
However, (seemingly) if and only if I then include the afermentioned client component do I sometimes receive this instead.
As is shown, very shortly after the socket connects to the server, it unexpectedly closes, with code 1005.
Now, unsuprisingly the socket stops receiving further communication from my server, and as such my application cannot function as intended as it is missing the required socket connection. (The socket that remains active has its event listeners cleaned up by my useEffect hook).
I should also note that when the page is refreshed (and the sockets close as I believe they should), the server logs them as closing with code 1001 like so:
I have no idea as to why this socket is closing, I am not super familiar with websockets so the error is likely a fault of my own and not the packages, however the fact that it does not happen consistently makes me even more bewildered as to what the cause might be. Any help would be appreciated, even if they are just suspicions, I am happy to try anything.
I will link the files in my project that I believe to be of note:
I am using next v14.1.1 and next-ws v1.0.1
I am using next-ws's built in
WebSocketProvider
component anduseWebSocket
hook, in order to establish and reference a websocket connection. I have come to find that when inspecting dev tools i can see that 2 websocket connections are established when the WebSocketProvider component is accessed. This is understandable as I am in development and as such react strictmode is enabled - however by inspecting chrome dev tools'network > messages
tab I can see that both connections remain open as they continue to receive data from my server.\
This is not in itself breaking for me, as my server can handle a user having multiple open socket connections, although I do wonder if it is intentional and perhaps not the case that only one connection should remain open and instead some useEffect clean-up callback is missing somewhere in next-ws?
The breaking issue that I am facing is that seemingly only when a certain client component of mine is loaded, does one of these two socket connections unexpectedly close with code
1005
very shortly after opening.This is what I typically see when in my server log's when I load the page (and
WebSocketProvider
establishes websocket connections)However, (seemingly) if and only if I then include the afermentioned client component do I sometimes receive this instead.
As is shown, very shortly after the socket connects to the server, it unexpectedly closes, with code
1005
.Now, unsuprisingly the socket stops receiving further communication from my server, and as such my application cannot function as intended as it is missing the required socket connection. (The socket that remains active has its event listeners cleaned up by my useEffect hook).
I should also note that when the page is refreshed (and the sockets close as I believe they should), the server logs them as closing with code
1001
like so:I have no idea as to why this socket is closing, I am not super familiar with websockets so the error is likely a fault of my own and not the packages, however the fact that it does not happen consistently makes me even more bewildered as to what the cause might be. Any help would be appreciated, even if they are just suspicions, I am happy to try anything.
I will link the files in my project that I believe to be of note:
The text was updated successfully, but these errors were encountered: