Skip to content

Commit

Permalink
fix(client): if the websocket fails to connect, wait on the socket ho…
Browse files Browse the repository at this point in the history
…st, not the ping host

The problem with checking the ping host is that the ping host can
pass, even if the socket host fails, leading to infinite reloads.

Infinite reloads are a bad way to deal with this failure.
This makes the failure less bad.

For examples, see:
#6814
#3093
  • Loading branch information
nicks committed Feb 9, 2022
1 parent b79fec9 commit 43deabe
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/vite/src/client/client.ts
Expand Up @@ -214,7 +214,9 @@ async function waitForSuccessfulPing(ms = 1000) {
// eslint-disable-next-line no-constant-condition
while (true) {
try {
await fetch(`${base}__vite_ping`)
// 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) {
await new Promise((resolve) => setTimeout(resolve, ms))
Expand Down

0 comments on commit 43deabe

Please sign in to comment.