Skip to content

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

@zhengjiaqi

Description

@zhengjiaqi

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions