Back

Realtime not reconnecting after tab sleeps

  • 0
  • Web
  • Realtime
  • Cloud
Josh
17 Mar, 2025, 18:12

I've been experiencing a bug where the web socket for the realtime API does not reconnect after my browser puts the page to sleep. Does anyone have any guidance regarding this?

I should add that I am using react JS and my realtime code is loaded in a useEffect.

TL;DR
Developers are struggling with the realtime WebSocket not reconnecting after the tab sleeps. One possible solution could be to create an event listener for page visibility and re-establish the connection when the page becomes visible again.
Kenny
17 Mar, 2025, 18:36

I don't believe there is anything in the realtime client to combat this, but you could create an event listener for page visibility, when the page becomes visible again re-establish the realtime connection.

Josh
17 Mar, 2025, 18:37

Thanks! Is it not bad practice to create a new realtime request when one already exists?

Kenny
17 Mar, 2025, 18:38

When the page goes to sleep the realtime connection is closed I believe, so you would need to re-establish it again.

Josh
17 Mar, 2025, 18:38

Got it, thanks

Kenny
17 Mar, 2025, 18:41

I don't see that the connection status is exposed so I'm not really sure how you would check if there is an active connection or not before creating a new one /:

Josh
17 Mar, 2025, 18:42

I'll try to just make a new one and see what happens. If it works, it works 🤷‍♂️

Kenny
17 Mar, 2025, 18:42

lmk how it goes

Josh
17 Mar, 2025, 18:47

Re running the function does not seem to open a new websocket when one already is open. I have yet to test its sleep recovery

Josh
17 Mar, 2025, 18:47

So far so good

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