Running multiple applications which proxy to each other breaks HMR

Đang mở
#30,321 0 bình luận 1 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
angular, typescript, vite

Hướng nghiên cứu

Bắt đầu với repository tái hiện được liên kết và README của nó để tái hiện HMR giữa các ứng dụng thông qua các proxy đã cấu hình. Sau đó, lần theo yêu cầu HMR của máy chủ phát triển Vite của Angular application builder, tập trung vào lý do phản hồi JavaScript đã cập nhật bị trống khi được lấy qua cổng của một ứng dụng khác. Công việc được coi là hoàn tất khi các bản cập nhật nóng được tải đúng cách giữa các ứng dụng được proxy và hành vi tải lại toàn bộ vẫn được giữ nguyên.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

area: @angular/build devkit/build-angular:dev-server freq1: low severity3: broken
Command

serve

Is this a regression?
  • Yes, this behavior used to work in the previous version
The previous version in which this bug was not present was

webpack-based dev-server HMR

Description

I work on a project which involves multiple separate Angular applications. They all live together in an Nx monorepository. It is the responsibility of one of these applications to handle user login. For ease of development, we have long configured each app and their proxies to handle forwarding to every other app, so that developers can start whichever apps are relevant to the work they are doing, log in using that app on its own port, and then navigate to other apps without needing to manually type a different port.

I hope this makes sense, I can try to explain more clearly if it doesn't. The important part is that we nearly always have more than one app running, and no matter which app's dev-server port you are on, they will always be able to forward requests intended for apps other than themselves. To achieve this each app has a unique base path which the proxy configuration uses to determine where to send requests.

We recently switched from the browser builder to the new application builder, and as a consequence the dev-server now uses Vite rather than Webpack. On the whole this has all been a great, apart from one thing: hot module reloading is broken cross-app.

I've created and linked a (somewhat minimal) reproduction repository below.

While investigating this myself, I noticed that when an app tries to hot update while on the "wrong" port, the part that seems to fail is fetching the new JavaScript file. The WebSocket connects just fine, receives the angular:component-update event just fine, and makes the request for the updated file just fine. The request even succeeds, actually, but the response is empty. Some screenshots for explanation:

WebSocket connects WebSocket receives update event JavaScript response is empty

It's worth noting that full-reload events work just fine, which is probably expected given the nature of what's failing about the hot reload.

That's as far as I've gotten. I'm not sure if there is some proxy configuration that I could do to fix this (I've tried some basic tweaks with no luck), or if this is a bug somewhere that needs to be fixed. But in the meantime, turning HMR off "fixes" things for us, though it isn't ideal of course.

Any help is appreciated, thank you!

Minimal Reproduction

https://github.com/tmercswims/ng-vite-mono-hmr

Includes reproduction steps in README.

Your Environment
Angular CLI: 19.2.12
Node: 22.15.0
Package Manager: npm 10.9.2
OS: darwin arm64

Angular: 19.2.11
... common, core, platform-browser, router

Package                      Version
------------------------------------------------------
@angular-devkit/architect       0.1902.12
@angular-devkit/build-angular   19.2.12
@angular-devkit/core            19.2.12
@angular-devkit/schematics      19.2.12
@angular/cli                    19.2.12
@angular/compiler               19.2.11
@angular/compiler-cli           19.2.11
@schematics/angular             19.2.12
rxjs                            7.8.2
zone.js                         0.15.0
Ngôn ngữ chính
TypeScript
Star
27k
Fork
11.8k
Merge trung bình
16 giờ 35 phút
Pull request đã merge (30 ngày)
176

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của angular/angular-cli

Tất cả issue của angular/angular-cli

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.