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

Add server.hmr.retry to solve frequent refresh caused by HMR WebSocket connection loss #6089

Closed
4 tasks done
zhengjiaqi opened this issue Dec 13, 2021 · 4 comments · Fixed by #9007
Closed
4 tasks done

Comments

@zhengjiaqi
Copy link

zhengjiaqi commented Dec 13, 2021

Clear and concise description of the problem

Currently vite will reload the page after the HMR ws link is lost.
In some cases, it may cause frequent page reloads.

In my case,In a hybrid app,we need to use a proxy to avoid domain name restrictions,this will cause the HMR WebSocket connection loss (This is our mistake, and I am trying to solve it),but this cause frequent page reloads.

Like this:
截屏2021-12-13 下午2 57 23

We comment out location.reload() in vite/dist/client/client.mjs to temporarily solve this problem.

And I found that others have encountered the same problem #5675

Suggested solution

There may be two ways to solve it:

  1. Reconnect HMR WebSocket connection instead of reloading the page,just like webpack-dev-server.
  2. Provide server.hmr.retry configuration to manually control whether to retry when the HMR WebSocket connection fails.

For option 2, I will provide a pr(#6090), the preview is like this:
截屏2021-12-13 下午2 53 01

Alternative

No response

Additional context

No response

Validations

@devxzero
Copy link

This problem doesn't just happen on connection loss, it can also happen when a client doesn't have websocket enabled or doesn't support websocket. In that case, the client browser will perform many page refreshes per second on the server immediately after the first page load, which can cause a hit on the server.

A reason why a client may disable websocket, is security. Websocket makes it possible for remote sites to perform local portscans at clients: https://nullsweep.com/why-is-this-website-port-scanning-me/

This page reload problem is also reported here: sveltejs/kit#3325
But it turned out to be an issue caused by Vite.

@clement4saunier
Copy link

How did you @zhengjiaqi fix the problem temporarily ? You meant update it on the browser or did you find a way to override this code ? issue is affecting my project

@zhengjiaqi
Copy link
Author

How did you @zhengjiaqi fix the problem temporarily ? You meant update it on the browser or did you find a way to override this code ? issue is affecting my project

@clement4saunier
You can refer to my commit : 2f2b2df

@gengjiawen
Copy link

Aha, #547 (comment) should be caused by this.

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