Skip to content

Commit

Permalink
fix: fix connection lost polling
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jun 24, 2020
1 parent 7fe66cc commit 298c78d
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ console.log('[vite] connecting...')
declare var __VUE_HMR_RUNTIME__: HMRRuntime

const socketProtocol = location.protocol === 'https:' ? 'wss' : 'ws'
const socketUrl = `${socketProtocol}://${location.host}/`
const socketUrl = `${socketProtocol}://${location.host}`
const socket = new WebSocket(socketUrl, 'vite-hmr')

function warnFailedFetch(err: Error, path: string | string[]) {
Expand Down Expand Up @@ -138,9 +138,13 @@ socket.addEventListener('message', async ({ data }) => {
socket.addEventListener('close', () => {
console.log(`[vite] server connection lost. polling for restart...`)
setInterval(() => {
new WebSocket(socketUrl).addEventListener('open', () => {
location.reload()
})
fetch('/')
.then(() => {
location.reload()
})
.catch((e) => {
/* ignore */
})
}, 1000)
})

Expand Down

0 comments on commit 298c78d

Please sign in to comment.