phoenixframework / phoenix_live_view

Rich, real-time user experiences with server-rendered HTML
https://hex.pm/packages/phoenix_live_view
MIT License
6k stars 906 forks source link

LiveView cannot reconnect gracefully after sleep in Safari iOS #3236

Closed aarroisi closed 2 months ago

aarroisi commented 2 months ago

Environment

Actual behavior

I open Safari, viewing a LiveView page that's connected via websocket. Everything works normal. Then I return to home screen, wait for about 30 seconds, then open Safari again. I saw the client-error with the usual "We can't find the internet" for about 10 seconds, then server-error with the usual "Something went wrong" for about 5 seconds, then the page refreshes automatically.

This error show in the Safari console (I open it using Developer mode, connected to a Mac): WebSocket connection to 'wss://snapid.fly.dev/live/websocket?_csrf_token=bx9McSpfWg4KKwA2bw5IFRIbaAMcRjY0ZO6Ann4zHmVT_z8dKy-we6g_&_track_static%5B0%5D=https%3A%2F%2Fsnapid.fly.dev%2Fassets%2Fapp-5a7552e0a439e4282910247c1a8a0bbf.css%3Fvsn%3Dd&_track_static%5B1%5D=https%3A%2F%2Fsnapid.fly.dev%2Fassets%2Fapp-de33ed4695286c6f8ed2174c6c58df8d.js%3Fvsn%3Dd&_track_static%5B2%5D=https%3A%2F%2Fsnapid.fly.dev%2Fassets%2Ftrix_config-36ea600ad547d43f806bcddf5ced6415.js%3Fvsn%3Dd&_mounts=0&_live_referer=undefined&vsn=2.0.0' failed: The operation couldn’t be completed. Operation timed out

You can try it yourself at https://snapid.fly.dev homescreen (my freshly installed toy project). The source code is here: https://github.com/aarroisi/snapid

Expected behavior

When I try it in Chrome iOS, this problem doesn't show up. In Chrome, after waking up from sleep, the client error message only show up for about half a second, then it reconnects without refresh. I expect this should also happen in Safari.

aarroisi commented 2 months ago

After I've tried many scenarios, the problem is completely gone when I switch back from Bandit to Cowboy. I guess the problem relies on the library, not the Phoenix / LiveView. I hope this will be fixed, since Bandit seems promising. For now, I will be using Cowboy.