This repository was archived by the owner on Jul 6, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +13
-9
lines changed Expand file tree Collapse file tree 1 file changed +13
-9
lines changed Original file line number Diff line number Diff line change @@ -68,6 +68,15 @@ export function connect(basePath: string) {
68
68
const { protocol, host } = location
69
69
const wsUrl = ( protocol === 'https:' ? 'wss' : 'ws' ) + '://' + host + basePath . replace ( / \/ + $ / , '' ) + '/_hmr'
70
70
const ws = new WebSocket ( wsUrl )
71
+ const contact = ( callback : ( ) => void ) => {
72
+ setTimeout ( ( ) => {
73
+ const ws = new WebSocket ( wsUrl )
74
+ ws . addEventListener ( 'open' , callback )
75
+ ws . addEventListener ( 'close' , ( ) => {
76
+ contact ( callback ) // retry
77
+ } )
78
+ } , 500 )
79
+ }
71
80
72
81
ws . addEventListener ( 'open' , ( ) => {
73
82
state . socket = ws
@@ -76,21 +85,16 @@ export function connect(basePath: string) {
76
85
} )
77
86
78
87
ws . addEventListener ( 'close' , ( ) => {
79
- if ( state . socket === null ) {
88
+ if ( state . socket !== null ) {
89
+ state . socket = null
90
+ console . log ( '[HMR] closed.' )
80
91
// re-connect
81
92
setTimeout ( ( ) => {
82
93
connect ( basePath )
83
94
} , 300 )
84
95
} else {
85
- state . socket = null
86
- console . log ( '[HMR] closed.' )
87
96
// reload the page when re-connected
88
- setInterval ( ( ) => {
89
- const ws = new WebSocket ( wsUrl )
90
- ws . addEventListener ( 'open' , ( ) => {
91
- location . reload ( )
92
- } )
93
- } , 300 )
97
+ contact ( ( ) => location . reload ( ) )
94
98
}
95
99
} )
96
100
You can’t perform that action at this time.
0 commit comments