You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When the server shuts down, the client starts sending periodic ping requests to check if the server is back up and then reload. These requests reach the middlewares defined by the users but it should probably be handled by vite before it reaches any of these like the initial websocket upgrade request does. There is also no reliable way to identify these requests for the middlewares to ignore it themselves.
Here it uses the no-cors mode so custom headers won't be sent along, can't use that to identify the ping request, but that can be worked around by abusing the Accept header, something like Accept: text/x-vite-ping and check that instead.
I could submit a PR, but can't tell which file would be responsible for intercepting it, is it ws.ts?
Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
We used to have a __vite_ping endpoint that the client will ping, but that was removed at #6819 and #8133, because it was changed to ping the HMR host instead of Vite's http server host. By default, both host are the same but some configuration can have custom setups.
I think it makes sense to handle this in the http server still, so adding a middleware here should be good enough. I'm also fine with the custom Accept header to recognize it.
Describe the bug
When the server shuts down, the client starts sending periodic ping requests to check if the server is back up and then reload. These requests reach the middlewares defined by the users but it should probably be handled by vite before it reaches any of these like the initial websocket upgrade request does. There is also no reliable way to identify these requests for the middlewares to ignore it themselves.
ref: sveltejs/kit#6910
ref: sveltejs/kit#7218
vite/packages/vite/src/client/client.ts
Lines 318 to 324 in c63ba3f
Here it uses the no-cors mode so custom headers won't be sent along, can't use that to identify the ping request, but that can be worked around by abusing the Accept header, something like
Accept: text/x-vite-ping
and check that instead.I could submit a PR, but can't tell which file would be responsible for intercepting it, is it
ws.ts
?Reproduction
https://github.com/gtm-nayan/vite-ping-repro
Steps to reproduce
Run pnpm install
Run pnpm dev
Open the page
Turn off dev server
Restart the dev server (ideally set a breakpoint on this line to avoid the clutter from unrelated requests)
Observe that the custom middleware from vite.config.js will have first logged the request URL from the ping request
System Info
npmPackages: vite: ^4.3.5 => 4.3.5
Used Package Manager
pnpm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: