Title: fix(core): preserve change detection strategy when overriding component by bethge · Pull Request #69731 · angular/angular · GitHub
Open Graph Title: fix(core): preserve change detection strategy when overriding component by bethge · Pull Request #69731 · angular/angular
X Title: fix(core): preserve change detection strategy when overriding component by bethge · Pull Request #69731 · angular/angular
Description: TestBed.overrideComponent previously caused JIT recompilation to overwrite a component's original ChangeDetectionStrategy. This ensures the component's existing ChangeDetectionStrategy is preserved when metadata overrides are applied. Disclaimer: Note that the root cause analysis of the bug and the solution were identified with the help of AI. I implemented the change, tests, and ran it against our codebase. The problem is in my opinion very much genuine but a different solution may be more appropriate. PR Checklist Please check if your PR fulfills the following requirements: The commit message follows our guidelines: https://github.com/angular/angular/blob/main/contributing-docs/commit-message-guidelines.md Tests for the changes have been added (for bug fixes / features) Docs have been added / updated (for bug fixes / features) PR Type What kind of change does this PR introduce? Bugfix Feature Code style update (formatting, local variables) Refactoring (no functional changes, no api changes) Build related changes CI related changes Documentation content changes angular.dev application / infrastructure changes Other... Please describe: What is the current behavior? When a component without explicit changeDetection strategy is overridden with TestBed.overrideComponent, the change detection strategy changes from OnPush (default) to Eager. This causes a mismatch between prod and test component behavior. AI's explanation: When TestBed.overrideComponent is called on a component, the component is added to TestBed's pendingComponents queue, forcing runtime JIT recompilation (compileTypesSync()). During this JIT recompilation, TestBed reconstructs the component metadata. Previously, the metadata decorator resolution defaulted changeDetection to ChangeDetectionStrategy.Eager, overwriting the component's existing (ɵcmp) Change Detection Strategy. As a result, an overridden component whose pre-compiled definition used ChangeDetectionStrategy.OnPush would unexpectedly run with ChangeDetectionStrategy.Default (Eager) in tests. Issue Number: N/A What is the new behavior? When compiling component overrides in TestBed, the implicit ChangeDetectionStrategy (onPush property on the pre-compiled ɵcmp definition) is preserved. Does this PR introduce a breaking change? Yes No Note on potential behavioral impact: While this is a bugfix restoring expected component behavior during testing, it could affect existing tests if consumers unknowingly relied on TestBed.overrideComponent silently reverting an OnPush component to Eager (Default) change detection. No such issue was found across our codebase. Other information Revealed during migration: This issue was discovered when removing redundant changeDetection: ChangeDetectionStrategy.OnPush declarations across our codebase. Removing the explicit declaration caused existing tests using TestBed.overrideComponent to fail, revealing that the JIT override path was silently altering the component's runtime change detection behavior. Why eager by default: I don't know if the Component decorator definition was left as Eager after the OnPush-as-default migration on purpose or accidentally.
Open Graph Description: TestBed.overrideComponent previously caused JIT recompilation to overwrite a component's original ChangeDetectionStrategy. This ensures the component's existing ChangeDetectionStrategy is p...
X Description: TestBed.overrideComponent previously caused JIT recompilation to overwrite a component's original ChangeDetectionStrategy. This ensures the component's existing ChangeDetectionStrat...
Opengraph URL: https://github.com/angular/angular/pull/69731
X: @github
Domain: github.com
| 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 | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:19d3f343-d683-e95f-e278-661fc593da8b |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | A89E:17FB7:CF4DE0:105F5A9:6B0138A6 |
| html-safe-nonce | 46ef12ca04b5fd61f127c00fc41d135e2d1b0357b4ac965b12fdbef42050fbc4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBODlFOjE3RkI3OkNGNERFMDoxMDVGNUE5OjZCMDEzOEE2IiwidmlzaXRvcl9pZCI6Ijg0MTk1MTA3Mjk1NzY2MjYzNDIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 93cd5d3cda3e7d1d18c0c8d08ef6990c95555858a6b18a64db269d970dedf368 |
| hovercard-subject-tag | pull_request:4029510040 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,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/angular/angular/pull/69731/files |
| twitter:image | https://avatars.githubusercontent.com/u/522575?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/522575?s=400&v=4 |
| og:image:alt | TestBed.overrideComponent previously caused JIT recompilation to overwrite a component's original ChangeDetectionStrategy. This ensures the component's existing ChangeDetectionStrategy is p... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| diff-view | unified |
| 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 full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width