Silent fail of preprendering
See original GitHub issue🐞 Bug report
Hi guys, firstly, I wanted to say thanks for your hard work, truly appreciate that 🙌
What modules are related to this issue?
- builders, but I’m not sure
- common
- express-engine
Is this a regression?
Probably, no
Description
So, I was playing around with the prerendering feature, but faced an issue - some of my routes were empty after prerendering script was executed successfully (a pre-rendered page contained only <router-outlet></router-outlet><!---->
instead of the component’s template).
It seems that I was able to track it down. The issue only appears when I’m using localStorage
in the component, but, I guess that could also be affected by the usage of any browser-specific API.
I believe that prerender
script should either fail or show some kind of warning in case non-existent API (in the context of server) is used.
🔬 Minimal Reproduction
- Initialize app via latest Angular CLI
- Add universal
- Add a new route/component. E.g.: a lazy module
dashboard
- Call
localStorage.getItem
in the constructor of the new component - Call prerender script (
npm run prerender -- --routes /dashboard /
) - See
dist/unversal-test/browser/dashboard/index.html
, there is content fromsrc/app/dashboard/dashboard.component.html
. And, there are no errors/warnings in the console
Here is the repository where I reproduced the issue, https://github.com/chernodub/ng-universal-reproduced-prerender-issue This is a breaking change https://github.com/chernodub/ng-universal-reproduced-prerender-issue/commit/656945bd4ad78e085f89fa30ad3d3c8e5acdc524, without it, prerender works fine
🔥 Exception or Error
No error or warning, that’s the problem. In case the application is somehow complex/advanced it may be very hard to understand, why prerender didn’t work 😦
🌍 Your Environment
- Dependencies
- MacOS Monterey 12.4
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:6 (6 by maintainers)
Top GitHub Comments
After looking a bit into this, it appears that the router is not re-throwing the error
Basically the below is not working as intended. https://github.com/angular/angular/blob/d583f85701b0424496e263bf1cbc2c619869437e/packages/router/src/router.ts#L1398-L1402
@atscott, I debugged this a bit more and as suspected this is indeed caused by the floating promises.
I tried to remove a number of floating promises (By patching the
node_modules
directly) and did indeed result in the error to bubble up correctly to the prerender worker.