Title: ExpressionChangedAfterItHasBeenCheckedError is not thrown if ChangeDetection.OnPush is used · Issue #45612 · angular/angular · GitHub
Open Graph Title: ExpressionChangedAfterItHasBeenCheckedError is not thrown if ChangeDetection.OnPush is used · Issue #45612 · angular/angular
X Title: ExpressionChangedAfterItHasBeenCheckedError is not thrown if ChangeDetection.OnPush is used · Issue #45612 · angular/angular
Description: Which @angular/* package(s) are the source of the bug? core Is this a regression? No Description When changing a template value while the change detection is taking place, the user is warned with an ExpressionChangedAfterItHasBeenChecked...
Open Graph Description: Which @angular/* package(s) are the source of the bug? core Is this a regression? No Description When changing a template value while the change detection is taking place, the user is warned with a...
X Description: Which @angular/* package(s) are the source of the bug? core Is this a regression? No Description When changing a template value while the change detection is taking place, the user is warned with a...
Opengraph URL: https://github.com/angular/angular/issues/45612
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"ExpressionChangedAfterItHasBeenCheckedError is not thrown if ChangeDetection.OnPush is used","articleBody":"### Which @angular/* package(s) are the source of the bug?\n\ncore\n\n### Is this a regression?\n\nNo\n\n### Description\n\nWhen changing a template value while the change detection is taking place, the user is warned with an `ExpressionChangedAfterItHasBeenCheckedError`.\r\nThis is not the case for components which use the `ChangeDetectionStrategy.OnPush` .\r\n\r\nBy doing some debugging I found the problem:\r\n\r\n1. The async pipe triggers a `markForCheck` for the component, while change detection is running.\r\n2. The refreshView [clears](https://github.com/angular/angular/blob/60b5a3de9d1c249d2322e56612d11d67aecc1d82/packages/core/src/render3/instructions/shared.ts#L477-L479) the dirty state of the component after the view has been checked.\r\n3. The [checkNoChanges](https://github.com/angular/angular/blob/60b5a3de9d1c249d2322e56612d11d67aecc1d82/packages/core/src/application_ref.ts#L846-L850) is performed, and the [refreshComponent](https://github.com/angular/angular/blob/60b5a3de9d1c249d2322e56612d11d67aecc1d82/packages/core/src/render3/instructions/shared.ts#L1751-L1753) function does not perform a refreshView for that component, since it is no longer dirty.\r\n\r\nThis results in no ExpressionChangedAfterItHasBeenCheckedError because the view is not checked, since its dirty status has been cleared in the change detection process\r\n\r\nThis can be really hard to debug without the warning. So I found a workaround for now, that is to add `|| isInCheckNoChangesMode()` to the [refreshView check](https://github.com/angular/angular/blob/60b5a3de9d1c249d2322e56612d11d67aecc1d82/packages/core/src/render3/instructions/shared.ts#L1751) so that it becomes `if (componentView[FLAGS] & (LViewFlags.CheckAlways | LViewFlags.Dirty) || isInCheckNoChangesMode()) {`. This is very ugly and imperformant, but at least it helps detect those errors.\n\n### Please provide a link to a minimal reproduction of the bug\n\nhttps://stackblitz.com/edit/angular-ivy-ked7hw?file=src/app/app.component.ts\n\n### Please provide the exception or error you saw\n\n_No response_\n\n### Please provide the environment you discovered this bug in (run `ng version`)\n\n```true\nAngular CLI: 13.3.2\r\nNode: 16.14.2\r\nPackage Manager: yarn 1.22.18\r\nOS: linux x64\r\n\r\nAngular: 13.3.2\r\n... animations, cdk, cdk-experimental, cli, common, compiler\r\n... compiler-cli, core, forms, material, material-moment-adapter\r\n... platform-browser, platform-browser-dynamic, router\r\n\r\nPackage Version\r\n---------------------------------------------------------\r\n@angular-devkit/architect 0.1303.2\r\n@angular-devkit/build-angular 13.3.2\r\n@angular-devkit/core 13.3.2\r\n@angular-devkit/schematics 13.3.2\r\n@schematics/angular 13.3.2\r\nng-packagr 13.3.0\r\nrxjs 7.5.5\r\ntypescript 4.6.3\r\nwebpack 5.72.0\n```\n\n\n### Anything else?\n\n_No response_","author":{"url":"https://github.com/skrtheboss","@type":"Person","name":"skrtheboss"},"datePublished":"2022-04-13T15:04:25Z","url":"https://github.com/angular/angular/issues/45612"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:9a801b5c-7db7-6296-398d-6276562f13f2 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C004:2564F:E6ABCA:130F211:6B00FFA3 |
| html-safe-nonce | 7efee0eaa3ad155f7a9155bb34b52aa08c7d63414f7cb3c9ea789ab00fb6c2e0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMDA0OjI1NjRGOkU2QUJDQToxMzBGMjExOjZCMDBGRkEzIiwidmlzaXRvcl9pZCI6IjQyMzgxNjc5OTE2ODgxNjczMzEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 54a1c84c7d3fea564f95d4f88627518ac4053e5232a4468ed869c7fddb8a8298 |
| hovercard-subject-tag | issue:1203431504 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular/45612/issue_layout |
| twitter:image | https://opengraph.githubassets.com/74d7da2896a0d30acead96c6bf33d3b0aa540d28ae20b36b9c4c629ffad62d9d/angular/angular/issues/45612 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/74d7da2896a0d30acead96c6bf33d3b0aa540d28ae20b36b9c4c629ffad62d9d/angular/angular/issues/45612 |
| og:image:alt | Which @angular/* package(s) are the source of the bug? core Is this a regression? No Description When changing a template value while the change detection is taking place, the user is warned with a... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | skrtheboss |
| hostname | github.com |
| expected-hostname | github.com |
| None | cb7fa109eca7d4156c889f474306b0e91336055e9adf8fd4684b61e49094d124 |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular git https://github.com/angular/angular.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 24195339 |
| octolytics-dimension-repository_nwo | angular/angular |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24195339 |
| octolytics-dimension-repository_network_root_nwo | angular/angular |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 2b59d31a4e44f08b7af67a4b67f8fd0af3befe2a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width