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

feat: allow use of clientPort without middlewareMode #4332

Merged
merged 2 commits into from Aug 27, 2021
Merged

feat: allow use of clientPort without middlewareMode #4332

merged 2 commits into from Aug 27, 2021

Conversation

Cretezy
Copy link
Contributor

@Cretezy Cretezy commented Jul 20, 2021

Description

Fixed #3737. Currently, clientPort is ignore when not in middleware mode.

Currently, it's impossible to run in normal mode behind a proxy due to the WebSocket connecting to the wrong port (#2474).

This can't be bypassed by disabling HMR (my preferred solution) because disabling HMR still keeps the WebSocket connection.

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 Commit 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.

@Shinigami92 Shinigami92 added feat: hmr p2-nice-to-have Not breaking anything but nice to have (priority) labels Jul 20, 2021
@Cretezy
Copy link
Contributor Author

Cretezy commented Jul 20, 2021

If someone needs this fixed, feel free to use patch-package with the following patch:

diff --git a/node_modules/vite/dist/node/chunks/dep-f2b4ca46.js b/node_modules/vite/dist/node/chunks/dep-f2b4ca46.js
index 875b021..f612e82 100644
--- a/node_modules/vite/dist/node/chunks/dep-f2b4ca46.js
+++ b/node_modules/vite/dist/node/chunks/dep-f2b4ca46.js
@@ -74496,14 +74496,14 @@ function clientInjectionsPlugin(config) {
                 const timeout = options.timeout || 30000;
                 const overlay = options.overlay !== false;
                 let port;
+                if (typeof config.server.hmr === 'object') {
+                  port = config.server.hmr.clientPort || config.server.hmr.port;
+                }
                 if (config.server.middlewareMode) {
-                    if (typeof config.server.hmr === 'object') {
-                        port = config.server.hmr.clientPort || config.server.hmr.port;
-                    }
                     port = String(port || 24678);
                 }
                 else {
-                    port = String(options.port || config.server.port);
+                    port = String(port || options.port || config.server.port);
                 }
                 let hmrBase = config.base;
                 if (options.path) {

@benmccann
Copy link
Collaborator

@Cretezy this PR will need to be rebased

@josh08h
Copy link

josh08h commented Aug 26, 2021

Awesome, thanks @Cretezy

@Cretezy
Copy link
Contributor Author

Cretezy commented Aug 26, 2021

@benmccann PR has been updated!

@patak-dev patak-dev changed the title Allow use of clientPort without middlewareMode feat: allow use of clientPort without middlewareMode Aug 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: hmr p2-nice-to-have Not breaking anything but nice to have (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

HMR clientPort option ignored in normal mode
6 participants