ably-js
ably-js copied to clipboard
usePresence error - Uncaught (in promise) Error: Connection closed
When using usePresence
, if I reload the page, I see the following error (with preserve log on)
ably.js:260 Uncaught (in promise) Error: Connection closed
at _ErrorInfo.fromValues (webpack-internal:///(app-pages-browser)/./node_modules/ably/build/ably.js:260:34)
at Object.closed (webpack-internal:///(app-pages-browser)/./node_modules/ably/build/ably.js:3697:27)
at WebSocketTransport.close (webpack-internal:///(app-pages-browser)/./node_modules/ably/build/ably.js:3749:52)
at _ConnectionManager.closeImpl (webpack-internal:///(app-pages-browser)/./node_modules/ably/build/ably.js:5113:42)
at _ConnectionManager.requestState (webpack-internal:///(app-pages-browser)/./node_modules/ably/build/ably.js:4898:12)
at eval (webpack-internal:///(app-pages-browser)/./node_modules/ably/build/ably.js:4197:16)
I wonder if maybe ably-js is trying to send an event like "leave" but the connection is already closed? Possibly related to this LOC?
The code to reproduce is very simple:
import { usePresence } from "ably/react"
const WhosOnlineList = ({ channelName }) => {
usePresence(channelName, { fullName: Math.random() })
return null
}
export default WhosOnlineList
Why does this matter?
It might not. I don't think you can technically be "present" on a channel if the connection has closed, but I'd like to understand the error better in case I should be structuring my React component differently.
Thank you!
I have the exact same error, except I don't use the hook. The sample code I use is in the comment - https://github.com/ably/ably-js/issues/1565#issuecomment-2078903030.
Hello @bookercodes , @nikitadubyk !
Thank you for reporting this and providing steps to reproduce. We're going to investigate this and get back with an update as soon as possible!
Hey @bookercodes , @nikitadubyk !
I was able to reproduce the issue with the provided code sample. I'm currently looking into its cause.
Same errors on page reload after updating to v2.
Hello, I am working on a tutorial I'm aiming to publish this week and keep getting this error. Can it safely be ignored or am I doing something wrong?
Hey @bookercodes ! You are not doing anything wrong; this is an issue on the ably-js side. We're planning to release a fix for it this week.
In the meantime, since this error occurs on page reload and essentially tries to close a connection a second time after it's already been closed, you can safely ignore it for now. The only real downside is that these errors might appear in your log monitoring tools.
This has been fixed in https://github.com/ably/ably-js/pull/1761 and will be released in the next patch version for ably-js package.
Hey, the fix for this issue has been released in 2.1.0 release of ably-js
.
Thank you for reporting this issue!
Great, thank you, I will update!