Repository navigation
Description
🐞 Bug report
What modules are related to this issue?
- builders
- common
- express-engine
Is this a regression?
I think this is a regression compared to the previous version I got installed which was 15.2.7
Description
HTTP calls seem to get stuck and do not finish serverside when they go out externally (to a real API).
🔬 Minimal Reproduction
1.- Download the finished example that is available in the Angular site: https://angular.io/guide/universal which is the tour of heroes
2.- Go to the app.module.ts and comment out the HttpClientInMemoryWebApiModule so that it simulates that there is a real HTTP call.
3.- Run the code using npm run dev:ssr for example
4.- Navigate to http://localhost:4200/dashboard
5.- See in the page that you have the Messages, the clear button and there is one message saying: HeroService: getHeroes failed: Http failure response for http://localhost:4200/api/heroes: 404 Not Found
6.- Right click on the page and click on View Page Source and see that all static code that needs to be rendered pre-HTTP call gets rendered on the page such as the Tour of Heroes, the Dashboard tab or the heroes tab is rendered however things like the Messages section (H2) or the actual message itself is not.
🔥 Exception or Error
I can see the following error in logs of the server
NetworkError
at send (./node_modules/xhr2/lib/xhr2.js:281:19)
at observer (./node_modules/@angular/common/fesm2022/http.mjs:1969:21)
at _trySubscribe (./node_modules/rxjs/dist/cjs/internal/Observable.js:41:25)
at cb (./node_modules/rxjs/dist/cjs/internal/Observable.js:35:31)
at errorContext (./node_modules/rxjs/dist/cjs/internal/util/errorContext.js:22:9)
at subscribe (./node_modules/rxjs/dist/cjs/internal/Observable.js:26:24)
at onNext (./node_modules/rxjs/dist/cjs/internal/operators/switchMap.js:17:63)
at _next (./node_modules/rxjs/dist/cjs/internal/operators/OperatorSubscriber.js:33:21)
at next (./node_modules/rxjs/dist/cjs/internal/Subscriber.js:51:18)
at <anonymous> (./node_modules/rxjs/dist/cjs/internal/observable/innerFrom.js:120:28)
However although the error (I am not sure) is related to a real 404, that should be handled in the application and the message should be rendered.
🌍 Your Environment
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI: 16.0.2
Node: 18.10.0
Package Manager: npm 8.19.2
OS: win32 x64
Angular: 16.0.2
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, platform-server
... router
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1600.2
@angular-devkit/build-angular 16.0.2
@angular-devkit/core 16.0.2
@angular-devkit/schematics 16.0.2
@nguniversal/builders 16.0.2
@nguniversal/express-engine 16.0.2
@schematics/angular 16.0.2
rxjs 7.8.1
typescript 4.9.5
Activity
matthew-whitfield-uk commentedon May 20, 2023
I have also been experiencing issues with server-side HTTP calls when upgrading from 16.0.0-rc.0 to 16.0.2.
The HTML rendered on the server side by angular universal doesn't seem to wait for HTTP calls to complete before sending the HTML to the user. The affects things like TransferState, which can store an HTTP response in the rendered HTML for the user to pick up, but in 16.0.2 it doesn't get included in the HTML.
It only seems to affect lazy loaded routes, the main AppModule component will wait for HTTP calls / setTimeoutes etc to complete before rendering the page and sending it to the user. However, any lazy-loaded routes won't wait, and so the server-rendered HTML won't include the results of any such requests.
Beforehand, angular universal would wait for these to complete on all routes before building the page.
Not sure if separate issue, or if this is some new config I am missing with the upgrade.
jvyden commentedon May 20, 2023
Getting a similar issue to Matthew, with the notable exception that in addition to not seeing the elements in the HTML I get an error in console upon page render depending on the request I make:
Interestingly, if I try to log the result in a request's observer that doesn't fire this error, the result appears as expected:

CarlosTorrecillas commentedon May 21, 2023
@matthew-whitfield-uk that fits into the behavior I am seeing. The information I don't know about is "what happens" to the actual HTTP request since my logs (on another application) does not show anything. Hopefully we get some feedback soon from the Angular team - since that's for me is a blocker for the upgrade
alan-agius4 commentedon May 22, 2023
I actually managed to replicate the problem and I am looking into it.
CarlosTorrecillas commentedon May 22, 2023
I have the repo ready for you in case you wanted: https://github.com/CarlosTorrecillas/universal-issue but seems you are already on it. Thanks @alan-agius4 !
CarlosTorrecillas commentedon May 24, 2023
Do you have an ETA for this code to be merged? It is just from the upgrade planning perspective to get an idea of when this can be available. Thanks a lot!
fix(http): create macrotask during request handling instead of load s…
alan-agius4 commentedon May 24, 2023
The fix for this should be released on NPM later today.
angular-automatic-lock-bot commentedon Jun 24, 2023
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.
fix(http): create macrotask during request handling instead of load s…