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 configuration of the vite HMR server #28517

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

RGunning
Copy link

@RGunning RGunning commented Sep 27, 2024

Vite allows additional configuration options for the HMR server that let the user set the port, protocol and host etc. of the HMR server.

Configuring HMR server to run on a different port to the main application fixes the issue

PR Checklist

Please check to confirm your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Currently it is impossible to configure the vite HMR server as this configuration option is not made available.

There is a bug in vite/browserstack which currently prevents running a local application using browserstack as the page will reload every ~50 seconds due to the websocket connection being lost. For some reason this only occurs when the application and the HMR are being served on the same port, resulting in the following error being thrown client:529 WebSocket connection to 'ws://localhost:4200/' failed: Unrecognized frame opcode: 5.
On receiving this error vite triggers a reload https://github.com/vitejs/vite/blob/eb08f605ddadef99a5d68f55de143e3e47c91618/packages/vite/src/client/client.ts#L106-L108

Issue Number: N/A

What is the new behavior?

It is now possible to configure the hmr configuration in the angular.json making it possible to configure more advanced hmr settings (https://vitejs.dev/config/server-options.html#server-hmr).

A use case of this is that it allows a custom hmr config which bypasses the browserstack error seen above.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Vite allows additional configuration options for the HMR server that let the user set the port, protocol and host etc. of the HMR server.

Whilst running a local Angular application with browserstack a websocket error gets thrown when the application and the HMR are being served on the same port `client:529 WebSocket connection to 'ws://localhost:4200/' failed: Unrecognized frame opcode: 5`. This results in the vite client force reloading the page https://github.com/vitejs/vite/blob/eb08f605ddadef99a5d68f55de143e3e47c91618/packages/vite/src/client/client.ts#L106-L108

Configuring HMR server to run on a different port to the main application fixes the issue
@angular-robot angular-robot bot added the detected: feature PR contains a feature commit label Sep 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
detected: feature PR contains a feature commit
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant