Skip to content

Commit

Permalink
fix: avoid creating multiple promises
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Apr 3, 2023
1 parent 62af5bc commit 462597b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/vite/src/client/client.ts
Expand Up @@ -328,6 +328,8 @@ async function waitForSuccessfulPing(
return false
}

let waitForWindowShowPromise: Promise<void> | undefined

// eslint-disable-next-line no-constant-condition
while (true) {
if (document.visibilityState === 'visible') {
Expand All @@ -336,7 +338,12 @@ async function waitForSuccessfulPing(
}
await wait(ms)
} else {
await Promise.race([wait(ms), waitForWindowShow()])
if (!waitForWindowShowPromise) {
waitForWindowShowPromise = waitForWindowShow().then(() => {
waitForWindowShowPromise = undefined
})
}
await Promise.race([wait(ms), waitForWindowShowPromise])
}
}
}
Expand Down

0 comments on commit 462597b

Please sign in to comment.