File tree 1 file changed +14
-1
lines changed
packages/next/src/client/dev/error-overlay
1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -26,11 +26,14 @@ export function sendMessage(data: string) {
26
26
return source . send ( data )
27
27
}
28
28
29
+ let reconnections = 0
30
+
29
31
export function connectHMR ( options : { path : string ; assetPrefix : string } ) {
30
32
function init ( ) {
31
33
if ( source ) source . close ( )
32
34
33
35
function handleOnline ( ) {
36
+ reconnections = 0
34
37
window . console . log ( '[HMR] connected' )
35
38
}
36
39
@@ -42,11 +45,21 @@ export function connectHMR(options: { path: string; assetPrefix: string }) {
42
45
}
43
46
}
44
47
48
+ let timer : ReturnType < typeof setTimeout >
45
49
function handleDisconnect ( ) {
46
50
source . onerror = null
47
51
source . onclose = null
48
52
source . close ( )
49
- init ( )
53
+ reconnections ++
54
+ // After 25 reconnects we'll want to reload the page as it indicates the dev server is no longer running.
55
+ if ( reconnections > 25 ) {
56
+ window . location . reload ( )
57
+ return
58
+ }
59
+
60
+ clearTimeout ( timer )
61
+ // Try again after 5 seconds
62
+ timer = setTimeout ( init , reconnections > 5 ? 5000 : 1000 )
50
63
}
51
64
52
65
const { hostname, port } = location
You can’t perform that action at this time.
0 commit comments