File tree Expand file tree Collapse file tree 3 files changed +23
-16
lines changed
lib/playground_web/components Expand file tree Collapse file tree 3 files changed +23
-16
lines changed Original file line number Diff line number Diff line change 18
18
// Include phoenix_html to handle method=PUT/DELETE in forms and buttons.
19
19
import "phoenix_html"
20
20
// Establish Phoenix Socket and LiveView configuration.
21
- import { Socket } from "phoenix "
21
+ import CustomSocket from "./custom_socket "
22
22
import { LiveSocket } from "phoenix_live_view"
23
23
import topbar from "../vendor/topbar"
24
24
25
25
let csrfToken = document . querySelector ( "meta[name='csrf-token']" ) . getAttribute ( "content" )
26
- let liveSocket = new LiveSocket ( "/live" , Socket , {
26
+ let liveSocket = new LiveSocket ( "/live" , CustomSocket , {
27
27
longPollFallbackMs : 2500 ,
28
28
params : { _csrf_token : csrfToken } ,
29
29
} )
Original file line number Diff line number Diff line change
1
+ import { Socket } from "phoenix"
2
+
3
+ export default class CustomSocket extends Socket {
4
+ // Adapted from https://github.com/phoenixframework/phoenix/tree/v1.7.14/assets/js/phoenix
5
+ onConnClose = function ( event ) {
6
+ let closeCode = event && event . code
7
+ if ( this . hasLogger ( ) ) this . log ( "transport" , "close" , event )
8
+
9
+ // Extra closeCodes handling for Firefox
10
+ // see https://github.com/phoenixframework/phoenix/pull/5735#issuecomment-2167196419
11
+ if ( closeCode == 1000 || closeCode == 1001 ) this . channels . forEach ( ( c ) => c . leave ( ) )
12
+
13
+ this . triggerChanError ( )
14
+ this . clearHeartbeats ( )
15
+ if ( ! this . closeWasClean && closeCode !== 1000 ) {
16
+ this . reconnectTimer . scheduleTimeout ( )
17
+ }
18
+ this . stateChangeCallbacks . close . forEach ( ( [ , callback ] ) => callback ( event ) )
19
+ }
20
+ }
Original file line number Diff line number Diff line change @@ -155,7 +155,7 @@ defmodule PlaygroundWeb.CoreComponents do
155
155
id = "client-error "
156
156
kind = { :error }
157
157
title = { gettext ( "We can't find the internet" ) }
158
- phx-disconnected = { delayed_show ( ".phx-client-error #client-error" ) }
158
+ phx-disconnected = { show ( ".phx-client-error #client-error" ) }
159
159
phx-connected = { hide ( "#client-error" ) }
160
160
hidden
161
161
>
@@ -612,19 +612,6 @@ defmodule PlaygroundWeb.CoreComponents do
612
612
)
613
613
end
614
614
615
- # Workaround for "We can't find the internet" flashes on Firefox
616
- # https://github.com/phoenixframework/phoenix/issues/5102#issuecomment-1970738490
617
- def delayed_show ( js \\ % JS { } , selector ) do
618
- JS . show ( js ,
619
- to: selector ,
620
- time: 1300 ,
621
- transition:
622
- { "delay-1000 transition-all transform ease-out duration-300" ,
623
- "opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95" ,
624
- "opacity-100 translate-y-0 sm:scale-100" }
625
- )
626
- end
627
-
628
615
def hide ( js \\ % JS { } , selector ) do
629
616
JS . hide ( js ,
630
617
to: selector ,
You can’t perform that action at this time.
0 commit comments