Skip to content

fix(proxy): match the HMR upgrade path exactly like the ws server#5678

Merged
bjohansebas merged 7 commits into
webpack:mainfrom
UlisesGascon:fix/hmr-path-normalization
Jun 12, 2026
Merged

fix(proxy): match the HMR upgrade path exactly like the ws server#5678
bjohansebas merged 7 commits into
webpack:mainfrom
UlisesGascon:fix/hmr-path-normalization

Conversation

@UlisesGascon

Copy link
Copy Markdown
Member

No description provided.

…e configured path

Adds trailing slash, case variations, percent-encoded path, and
leading double slash to the existing HMR/proxy isolation tests so
that all URL shapes recognized as the HMR upgrade are treated
consistently.
Tighten the HMR-vs-proxy upgrade dispatch so URL variants of the
configured HMR path are consistently recognized as the HMR socket:

  - lowercase comparison (case-insensitive)
  - decode percent-encoding before comparison
  - strip trailing slashes
  - collapse leading multiple slashes so //foo is treated as /foo
    instead of being parsed as a scheme-relative URL
  - wrap URL parsing in try/catch so a malformed req.url does not
    raise an uncaught exception
@codecov

codecov Bot commented May 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.61%. Comparing base (93e8996) to head (0a1eddb).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5678   +/-   ##
=======================================
  Coverage   83.60%   83.61%           
=======================================
  Files          13       13           
  Lines        2086     2087    +1     
  Branches      773      774    +1     
=======================================
+ Hits         1744     1745    +1     
  Misses        306      306           
  Partials       36       36           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@alexander-akait

Copy link
Copy Markdown
Member

/cc @bjohansebas can you take a look, thanks

Comment thread lib/Server.js Outdated
Comment thread test/server/proxy-option.test.js Outdated
Comment thread lib/Server.js Outdated
@bjohansebas

Copy link
Copy Markdown
Member

Okay, I removed the normalization/decoding step so that it follows the ws implementation and avoids any unexpected edge cases. I'm also going to add tests for SockJS since it's still used in this version. It can be removed in the next major release.

@bjohansebas bjohansebas changed the title normalize HMR upgrade path comparison fix(proxy): match the HMR upgrade path exactly like the ws server Jun 10, 2026
@bjohansebas bjohansebas marked this pull request as ready for review June 10, 2026 18:08
Copilot AI review requested due to automatic review settings June 10, 2026 18:08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds a more faithful HMR WebSocket upgrade-path check when deciding whether to dispatch an upgrade event to user-defined WebSocket proxies, aligning the proxy “skip” behavior with how the ws server matches paths.

Changes:

  • Updated Server upgrade handling to compare the raw request target (with query stripped) against the configured HMR path.
  • Added a comprehensive regression test suite ensuring HMR upgrades are served locally while non-HMR upgrades are forwarded to user proxies (including ws, sockjs, custom paths, and disabled WS server cases).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
lib/Server.js Adjusts HMR upgrade-path matching to avoid URL normalization and match ws path handling semantics.
test/server/proxy-option.test.js Adds new tests covering HMR vs non-HMR upgrade dispatch behavior across WS server types and configurations.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread test/server/proxy-option.test.js
Comment thread test/server/proxy-option.test.js
Comment thread test/server/proxy-option.test.js Outdated
@bjohansebas

Copy link
Copy Markdown
Member

Interesting, Node 24 doesn't work because of Chrome-related issues.

Copilot AI review requested due to automatic review settings June 12, 2026 15:32

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

Comment thread lib/Server.js
Comment thread test/server/proxy-option.test.js Outdated
Comment thread .github/workflows/nodejs.yml
@bjohansebas bjohansebas merged commit 948d5e6 into webpack:main Jun 12, 2026
104 of 151 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants