Skip to content

Commit

Permalink
fix(client): detect ws close correctly (#18548)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red authored Nov 1, 2024
1 parent 1ed03c6 commit 637d31b
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions packages/vite/src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,19 @@ function setupWebSocket(
handleMessage(JSON.parse(data))
})

let willUnload = false
window.addEventListener(
'beforeunload',
() => {
willUnload = true
},
{ once: true },
)

// ping server
socket.addEventListener('close', async ({ wasClean }) => {
if (wasClean) return
socket.addEventListener('close', async () => {
// ignore close caused by top-level navigation
if (willUnload) return

if (!isOpened && onCloseWithoutOpen) {
onCloseWithoutOpen()
Expand Down

0 comments on commit 637d31b

Please sign in to comment.