Title: OnPush component in dev mode will only trigger change detection once. · Issue #39545 · angular/angular · GitHub
Open Graph Title: OnPush component in dev mode will only trigger change detection once. · Issue #39545 · angular/angular
X Title: OnPush component in dev mode will only trigger change detection once. · Issue #39545 · angular/angular
Description: Consider the following case. @Component({ template: `
Open Graph Description: Consider the following case. @Component({ template: `
X Description: Consider the following case. @Component({ template: ` <button (click)="noop()">Trigger change detection</button> <div>{{increment('componentView')}}</div> ...
Opengraph URL: https://github.com/angular/angular/issues/39545
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"OnPush component in dev mode will only trigger change detection once.","articleBody":"Consider the following case.\r\n\r\n```\r\n @Component({\r\n template: `\r\n \u003cbutton (click)=\"noop()\">Trigger change detection\u003c/button>\r\n \u003cdiv>{{increment('componentView')}}\u003c/div>\r\n `,\r\n changeDetection: ChangeDetectionStrategy.OnPush\r\n })\r\n class App {\r\n increment() {\r\n counters++;\r\n }\r\n noop() {}\r\n }\r\n const fixture = TestBed.createComponent(App);\r\n fixture.detectChanges();\r\n expect(counters).toEqual(2); // current behavior is 1 \r\n```\r\nThe reason is App is a OnPush component with a hostView, calling fixture.detectChanges() will run a detectChanges() and checkNoChanges() .\r\nAnd the App component is onPush, so the checkNoChanges() run will ignore App component, so the counters will be 1\r\nWhich is not correct.\r\n\r\nAnother case is:\r\n\r\n```\r\n it('works', () => {\r\n @Component({\r\n template: '{{message}}',\r\n changeDetection: ChangeDetectionStrategy.OnPush\r\n })\r\n class OnPushCmp {\r\n @Input() message = 'initial';\r\n ngAfterViewInit() {\r\n this.message = 'updated';\r\n }\r\n }\r\n const comp = TestBed.configureTestingModule({declarations: [OnPushCmp]}).createComponent(OnPushCmp);\r\n expect(() => comp.detectChanges()).toThrow(); // current behavior is not throw.\r\n });\r\n```\r\n\r\nThe reason is the same, the `checkNoChanges()` will skip the `OnPushCmp`, so the `ExpressionChanged` error is not thrown.\r\n\r\n\r\n\r\n","author":{"url":"https://github.com/JiaLiPassion","@type":"Person","name":"JiaLiPassion"},"datePublished":"2020-11-03T01:49:27Z","url":"https://github.com/angular/angular/issues/39545"}
| 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:9f02da22-81da-dafc-1262-828db798925b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B5FE:19E4BB:BDD3FD:F38EE3:6B00FD0A |
| html-safe-nonce | ffa4a324d6048da32ca8295a05fb79ad5320d20018d9899b45ac90b4834e4c18 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNUZFOjE5RTRCQjpCREQzRkQ6RjM4RUUzOjZCMDBGRDBBIiwidmlzaXRvcl9pZCI6IjYzNzQ5OTQwNTIwMDUyOTc0MTgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 33d496e779847606c5d54df445e64f768411020341145276426aa9fc6186cc10 |
| hovercard-subject-tag | issue:734956273 |
| 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/39545/issue_layout |
| twitter:image | https://opengraph.githubassets.com/49573e575b54ca386083acd3ae20ea8d0fd4a4db151de64b68b70c189a6a091f/angular/angular/issues/39545 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/49573e575b54ca386083acd3ae20ea8d0fd4a4db151de64b68b70c189a6a091f/angular/angular/issues/39545 |
| og:image:alt | Consider the following case. @Component({ template: ` {{increment('componentView')}} `, changeDetection: ChangeDetectionStrateg... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | JiaLiPassion |
| hostname | github.com |
| expected-hostname | github.com |
| None | e208d86428ec00a57ade75058166297440e8128a01e5287c31a53dc042bbf187 |
| 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 | 7dafd017fb7809a839c443dba08622af38e63c09 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width