I've got a strange problem that I hope is just a simple fix on my end. The change detection in Angular is not working only in production.
I've built a fairly complex app using Angular 7 and ngrx as state management. There are 2 main modules that are lazy loaded base on the route. The change detection strategy is OnPush and 99% of the app follows a pattern of data comes from server via ngrx effects to stateful components that then push the data into "dummy" presentational components via async pipe. Example:
this.loading$ = this.store.pipe(
select(selector.isLoading),
takeUntil(this.unsubscribe$)
);
<app-loading [loading]="loading$ | async"></app-loading>
On ng serve
and ng serve --prod
everything works as expected and there are no issues. However after running ng build --prod
and pushing the js files into our .net solution change detection ceases to work.
What do I mean by "ceases to work"? I mean it does not change any model or components unless a DOM event has taken place.
For example using the code shown as above there is a loading spinner that displays until data comes from the server. In production the spinner sits on the screen until you randomly click. Then the app refreshes and the data is displayed. This issue continues throughout the app. That is, this issue is not just happening there.
The app is loaded in an .cshtml file in a .Net solution like this:
<script type="text/javascript" src="runtime.js"></script>
<script type="text/javascript" src="polyfills.js"></script>
<script type="text/javascript" src="main.js"></script>
The lazy loaded modules are within the folder of the .cshtml file and are showing no errors so I must assume everything is wired up correctly.
Again this is only in the prod bundle. Not in dev or serve or prod mode serve.