-
Notifications
You must be signed in to change notification settings - Fork 963
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Flashing element on phx-connected / phx-disconnected #2945
Comments
It has to do with the way that firefox and chrome handle websockets closing the connection, page refresh doesn't trigger the close event on chrome, so it starts "clean" and then the webserver just starts a new connection, while in firefox you need to check the disconnection. After a bit of research I found this answer on stack overflow. If you want to check what happens in live_view just add this line of code after console.log(liveSocket.socket.conn.addEventListener("close", (evt) => console.log(evt))); After reload in firefox you'll get something like
While in chrome you'll get an Also, this isn't a live_view issue, probably a phoenix socket issue about how it handle disconnects and the wasClean property, I would start debugging putting a console log in this part of the code and if there's no result I would check all the others Ok, did a bit of an exploration here and it seems that chrome and safari doesn't send the if (closeCode !== 1001) {
this.triggerChanError()
} the error disappears. It's pretty late right now and I did not test it extensively, but I think that this should be enough and will not create any issues, but I'm hoping to hear more opinions before submitting a PR. |
As far as I understand it, this is only happens when the the user hard refreshes the page, right? In such cases, I don't consider this an issue. The browser is losing connection. You can override and try to debounce yourself in firefox, but it's going to be tricky. 1001 can be either the client going away or the server, so you want to be careful to actually show the error disconnected state if it was indeed the server going away long term. liveSocket.getSocket().onClose(e => {
if(e.code === 1001){ document.querySelectorAll("[phx-disconnected]").forEach(el => {
// hide now and show later if we are still disconnected and here
})
}) |
It happens randomly when clicking on logo from register page. But it does not flash when switching between two live views, ie. clicking between two register links generated with
flashing - |
fwiw: I thought the flickering of that alert box is somewhat distracting during development. |
Our customer is also not happy about this flashing box when reloading the page or when coming back to if after the browser was long in the background (especially Firefox). |
This should be fixed with #3680. |
Environment
Actual behavior
The exact same problem as #2276
The
phx-disconnected
binding is executed on every page load before the LiveSocket is connected. This causes theflash_group
to appear, although that only happens in Firefox (120.0.1), Chrome and Safari work as expected.That can be verified in a fresh new Phoenix that just got generated.
Screen.Recording.2023-12-07.at.11.54.13.mov
The text was updated successfully, but these errors were encountered: