ably / ably-js

Javascript, Node, Typescript, React, React Native client library SDK for Ably realtime messaging service
https://ably.com/download
Apache License 2.0
313 stars 55 forks source link

usePresence error - Uncaught (in promise) Error: Connection closed #1753

Closed bookercodes closed 3 months ago

bookercodes commented 4 months ago

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!

┆Issue is synchronized with this Jira Task by Unito

nikitadubyk commented 4 months ago

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.

VeskeR commented 4 months ago

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!

VeskeR commented 4 months ago

Hey @bookercodes , @nikitadubyk !

I was able to reproduce the issue with the provided code sample. I'm currently looking into its cause.

Elmosh commented 4 months ago

Same errors on page reload after updating to v2.

bookercodes commented 4 months ago

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?

VeskeR commented 4 months ago

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.

VeskeR commented 3 months ago

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.

VeskeR commented 3 months ago

Hey, the fix for this issue has been released in 2.1.0 release of ably-js. Thank you for reporting this issue!

bookercodes commented 3 months ago

Great, thank you, I will update!