Back

Realtime unsubscribe issue, with useEffect Hook

  • 1
  • Web
  • Realtime
another
11 Jun, 2023, 04:34

Hi, i am not able to unsubscribe after the unmount, here is the code

TypeScript
        const unsubscribe = client.subscribe(

            `databases.${process.env.NEXT_PUBLIC_DATABASE_ID}.collections.${process.env.NEXT_PUBLIC_CHATS_COLLECTION}.documents`,

            response => {
           console.log(response); 
},
        )

        return () => {
            unsubscribe();
            console.log('unsubscribed');
        }
    }, [])```


realtime connection staying the same in appwrite dashboard, even after  unmount.
TL;DR
The user is experiencing an issue where they are unable to unsubscribe after unmounting a component. They are using the `useEffect` hook with a client subscription. The issue seems to only occur when switching pages using the `next/Link` component. The realtime connection is not being closed in the Appwrite dashboard even after unmounting. The solution is to check the network logs and switch to the WS tab to confirm the websocket is disconnected. Additionally, the usage stats might be delayed due to ongoing rewriting.
another
11 Jun, 2023, 04:36

i also notice something, it's only happens, when i switch pages with next/Link component, and not with ahref tags

Drake
11 Jun, 2023, 05:21

Do you have subscriptions on some other part of your app? Or another page?

Drake
11 Jun, 2023, 05:25

Is the unsubscribed being logged?

another
11 Jun, 2023, 06:31

i am importing {client} variable from appwrite-utils.js and then using it in a chat page, i am not using it anywhere else. And yes, unsubscribed log is showing in the console.

Drake
11 Jun, 2023, 15:27

Oh...you're saying the usage stats are not up to date...the usage stuff might be delayed. We're rewriting all of that.

Drake
11 Jun, 2023, 15:28

You should be fine. You can check the network logs and switch to the WS tab to confirm the websocket is disconnected

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more