Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

优化waitForSuccessfulPing方法 #4501

Closed
4 tasks done
fexpanda opened this issue Aug 4, 2021 · 4 comments · Fixed by #5466
Closed
4 tasks done

优化waitForSuccessfulPing方法 #4501

fexpanda opened this issue Aug 4, 2021 · 4 comments · Fixed by #5466

Comments

@fexpanda
Copy link

fexpanda commented Aug 4, 2021

Clear and concise description of the problem

仅当网络故障时或请求被阻止时放弃轮询,我觉得是不够的,可以判断一下fetch结果中的ok属性,true时才放弃轮询

Suggested solution

const rst = await fetch(`${base}__vite_ping`)
if (rst.ok) {
    break
} else {
    throw new Error()
}

Alternative

No response

Additional context

No response

Validations

@sodatea
Copy link
Member

sodatea commented Aug 4, 2021

具体什么场景下会有区别?

@fexpanda
Copy link
Author

fexpanda commented Aug 4, 2021 via email

@mwarnerdotme
Copy link
Contributor

I was having the same issue in my project where we are using a proxy to serve the Vite dev server. The suggested solution is working for me after applying it to line 338 in node_modules/vite/dist/client/client.mjs. Thanks @wulify!

More detail on the issue: for some reason, the error thrown by the fetch request in the current code is not causing the catch statement to catch any errors (and properly try again after the ms timeout), but if you check for rst.ok manually (as suggested) you can then throw an error manually and the original logic works fine. Simple fix, but effective!

If there isn't a PR already made for this, I'd be happy to submit it so that we don't have to fork Vite or apply our own patch going forward.

@fexpanda
Copy link
Author

fexpanda commented Oct 28, 2021 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants