-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
fix: use websocket to test server liveness before client reload #17891
fix: use websocket to test server liveness before client reload #17891
Conversation
Run & review this pull request in StackBlitz Codeflow. |
My team applied these changes to vite locally and tried it with 5 different Nuxt 3 based applications running behind a traefik based https reverse proxy. This change massively improves the DX for us as we no longer have to constantly full-page reload our apps especially when vite is still booting. I'd love to see this merged ❤️ Thanks @hi-ogawa, this gives us back so much productivity! |
Can confirm, this also fixes my issue. I use vite for SSR by adding it to my express server (pretty much exactly this code in res.status(200).set({
'Content-Type': 'text/html',
'Cross-Origin-Opener-Policy': 'same-origin',
'Cross-Origin-Embedder-Policy': 'require-corp',
}).end(html); Before this patch, after a server stop/start or reload, the HMR ping over HTTP would loop forever and fail with a 426 status (what Firefox shows me anyway) and console logs show the request failed due to CORS. I couldn't find any easy way to configure the HMR server to add CORS headers after a solid hour of searching. Eventually landed here, tried this fix, and it works. Pinging over WS instead of over HTTP certainly makes more sense IMO especially since the target connection is WS anyway; why ping over HTTP when the goal is to get a WS connection set up? Browsers have different rules for HTTP vs WS regarding CORS so pinging over WS removes that entire class of issues. |
New test is flaky but I'm not sure what's going on. Locally, this command can fail if I run a few times. pnpm test-serve playground/client-reload |
Though tests could be still flaky, but I added some workaround by skipping some tests and retry. |
It passes on my PC even if I enable all tests. Did you try |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
On my PC, it happens quite consistently (like 1 in 2 or 3 runs) by running it I couldn't figure out a way to debug the issue. What does |
It'll run playwright in non-headless mode. Maybe you can find out what's happening. Although, it may not reproduce with it. |
Hmm, unfortunately it doesn't reproduce with Let me tweak the test to only skip on linux. |
Well, it just failed on macos as well. I'll re-run a few times and probably I'll put back skip and retry. |
This reverts commit 3af732c.
I fixed the test fail in 91e7edf. It seems the HTTP server was sending an empty response because the WS server listens before the HTTP server. |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
Hmm, it seems my change broke a bunch of tests. |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
Wow, awesome finding. I still cannot see it reproduced in the browser, but the fix makes sense! |
I did a unsophisticated push and CI debug😅 |
Great work! I think it would be good to have this in Vite 6. I added it to the milestone. |
@patak-dev why not in v5.x? This is a great bug fix IMO. |
It because this PR is not small enough or urgent enough to release in a patch and we don't have a plan to release a minor in v5. |
/ecosystem-ci run |
📝 Ran ecosystem CI on
✅ analogjs, histoire, ladle, laravel, marko, previewjs, quasar, qwik, rakkas, storybook, unocss, vite-environment-examples, vite-plugin-pwa, vite-plugin-react, vite-plugin-react-swc, vite-plugin-vue, vite-setup-catalogue, vitepress, vuepress |
nuxt is failing on main branch and the fails have the same errors with the latest scheduled ones so should be fine. |
Description
This PR makes
waitForSuccessfulPing
more robust by testing Vite server liveness based on websocket connection as suggested in #5675 (comment)Testing #13125
pnpm -C playground/tailwind dev
cloudflared tunnel --url http://localhost:5173/
Testing #16536 (this one is added as a test case)
pnpm -C playground/tailwind dev
with a following server config