Skip to content

Commit

Permalink
fix(client): wait on the socket host, not the ping host (#6819)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicks committed May 10, 2022
1 parent 4abfee6 commit ae56e47
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions packages/vite/src/client/client.ts
Expand Up @@ -201,12 +201,10 @@ async function waitForSuccessfulPing(ms = 1000) {
// eslint-disable-next-line no-constant-condition
while (true) {
try {
const pingResponse = await fetch(`${base}__vite_ping`)

// success - 2xx status code
if (pingResponse.ok) break
// failure - non-2xx status code
else throw new Error()
// A fetch on a websocket URL will return a successful promise with status 400,
// but will reject a networking error.
await fetch(`${location.protocol}//${socketHost}`)
break
} catch (e) {
// wait ms before attempting to ping again
await new Promise((resolve) => setTimeout(resolve, ms))
Expand Down

0 comments on commit ae56e47

Please sign in to comment.