Skip to content

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
@alan-agius4
Copy link
Collaborator

Thanks for this contribution. Before extending our APIs, we'd like to explore alternative solutions that don't require modifying the public serving API.

For testing purposes, you can disable live reloading by using the --no-live-reload option.

If the issue persists, please open a ticket with a minimal reproduction. Thank you!

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Apr 26, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

detected: feature PR contains a feature commit

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants