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

fix: allow using vite as a proxy for another vite server #13218

Merged
merged 3 commits into from Jun 15, 2023

Conversation

divdavem
Copy link
Contributor

@divdavem divdavem commented May 16, 2023

Description

The goal of this PR is to allow using vite as a proxy for another vite server, with HMR still working for the upstream server.

Additional context

Currently vite prevents any websocket connection with the vite-hmr websocket protocol from being forwarded to another server. I think it is not correct, vite should only handle itself the connection if it has the correct URL (in addition to the correct websocket protocol), and it should be able forward websocket connections to another server whatever the protocol it uses.

What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the PR Title Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@stackblitz
Copy link

stackblitz bot commented May 16, 2023

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@divdavem divdavem changed the title feat: allow using vite as a proxy for another vite server fix: allow using vite as a proxy for another vite server May 23, 2023
@divdavem divdavem marked this pull request as ready for review May 23, 2023 16:07
@patak-dev
Copy link
Member

Would you explain your use case? Why is this feature needed in your setup?

@patak-dev patak-dev added the p2-to-be-discussed Enhancement under consideration (priority) label May 24, 2023
@divdavem
Copy link
Contributor Author

divdavem commented May 24, 2023

Would you explain your use case? Why is this feature needed in your setup?

The test case that I have included in this PR is basically a very simple reproduction of what we actually do.
We have an application (using vite) that includes multiple applications in iframes. During development, we use the proxy feature of vite in the outer application to include the inner applications at specific paths.
Some of the inner applications use vite, some others don't. One of the inner applications use angular, and the automatic refresh when changing a file works without issue (because the websocket used by the angular cli does not have vite-hmr in the Sec-WebSocket-Protocol header). The automatic refresh of inner applications that use vite do not work in the outer application that use vite. I opened this PR to fix this bug.

@patak-dev
Copy link
Member

/ecosystem-ci run

@vite-ecosystem-ci
Copy link

vite-ecosystem-ci bot commented May 24, 2023

📝 Ran ecosystem CI: Open

suite result
astro ✅ success
histoire ✅ success
iles ✅ success
ladle ✅ success
laravel ✅ success
marko ✅ success
nuxt ❌ failure
nx ✅ success
previewjs ✅ success
qwik ✅ success
rakkas ✅ success
sveltekit ✅ success
unocss ✅ success
vite-plugin-pwa ✅ success
vite-plugin-ssr ✅ success
vite-plugin-react ✅ success
vite-plugin-react-pages ✅ success
vite-plugin-react-swc ✅ success
vite-plugin-svelte ✅ success
vite-plugin-vue ✅ success
vite-setup-catalogue ✅ success
vitepress ✅ success
vitest ✅ success

Copy link
Member

@sapphi-red sapphi-red left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought this is similar with vitejs/vite-plugin-vue#21. But actually this was different from that one.

I think this won't cause any issues for others. 👍

@patak-dev patak-dev enabled auto-merge (squash) June 15, 2023 12:48
@patak-dev patak-dev merged commit 711dd80 into vitejs:main Jun 15, 2023
13 checks passed
@divdavem
Copy link
Contributor Author

@sapphi-red @patak-dev Thank you for reviewing and merging my PR!

@bluwy bluwy mentioned this pull request Jul 13, 2023
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p2-to-be-discussed Enhancement under consideration (priority)
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

3 participants