Title: JIT (TestBed) still defaults changeDetection to Eager, AOT correctly defaults to OnPush · Issue #70262 · angular/angular · GitHub
Open Graph Title: JIT (TestBed) still defaults changeDetection to Eager, AOT correctly defaults to OnPush · Issue #70262 · angular/angular
X Title: JIT (TestBed) still defaults changeDetection to Eager, AOT correctly defaults to OnPush · Issue #70262 · angular/angular
Description: Description @Component() without an explicit changeDetection behaves differently depending on how it's compiled: AOT (production build) → OnPush (the documented default since v22, #67687) JIT (TestBed, Jest, etc.) → still Eager So the ex...
Open Graph Description: Description @Component() without an explicit changeDetection behaves differently depending on how it's compiled: AOT (production build) → OnPush (the documented default since v22, #67687) JIT (Test...
X Description: Description @Component() without an explicit changeDetection behaves differently depending on how it's compiled: AOT (production build) → OnPush (the documented default since v22, #67687) JIT (...
Opengraph URL: https://github.com/angular/angular/issues/70262
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"JIT (TestBed) still defaults changeDetection to Eager, AOT correctly defaults to OnPush","articleBody":"## Description\n\n`@Component()` without an explicit `changeDetection` behaves differently depending on how it's compiled:\n\n- **AOT** (production build) → `OnPush` (the documented default since v22, #67687)\n- **JIT** (TestBed, Jest, etc.) → still `Eager`\n\nSo the exact same component can pass its tests and then behave differently in prod, or vice versa.\n\n## Reproduction\n\n```ts\n@Component({\n selector: 'my-comp',\n template: '',\n})\nclass MyComponent {}\n```\n\nCompile this with `ngc`/a normal `ng build` → `OnPush`.\nRun it through `TestBed.createComponent(MyComponent)` in a spec → `Eager`.\n\nWe hit this for real: after upgrading to v22, we removed an explicit `changeDetection: ChangeDetectionStrategy.OnPush` from a component (reasoning: it's the default now, why write it). One TestBed spec started failing (`signal read during notification phase`) — only under Jest, not in the actual app.\n\n## Root cause\n\n`packages/core/src/metadata/directives.ts` still hardcodes the JIT decorator's own default:\n\n```ts\n(c: Component = {}) => ({changeDetection: ChangeDetectionStrategy.Eager, ...c}),\n```\n\nThis line wasn't touched by #67687, which only updated the AOT compiler and the JIT \"declare component\" linking path (`convertDeclareComponentFacadeToMetadata` in `jit_compiler_facade.ts`), not the plain decorator that TestBed/Jest actually exercise.\n\nThere's even a TODO for this exact spot, removed the same day #67687 merged, without the value being updated:\n\n```diff\n- // TODO(jeanmeche): remove the ts-ignore when OnPush is the default\n- // @ts-ignore\n (c: Component = {}) => ({changeDetection: ChangeDetectionStrategy.Eager, ...c}),\n```\n(commit `cf3b7fe489`)\n\nStill reproduces on `main` and on the latest published `22.1.2`.\n\n## Fix\n\nPR: #70261 — one-line default flip + a regression test. Couldn't run the full internal test suite locally, so CI may turn up other spec files relying on the old JIT default.\n\n## Environment\n\nAngular: 22.1.2 (also reproduces on `main`)","author":{"url":"https://github.com/ValeraGin","@type":"Person","name":"ValeraGin"},"datePublished":"2026-08-18T23:18:04Z","url":"https://github.com/angular/angular/issues/70262"}
| 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:9742cea6-b6ef-9a10-0285-132b38aa3843 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A7C0:399E4B:15443AF:1C3D96F:6B012EAD |
| html-safe-nonce | a89aa276345bae80f04ca44b2e8b3c095efcbc8e6b469445dd0ced133d408079 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBN0MwOjM5OUU0QjoxNTQ0M0FGOjFDM0Q5NkY6NkIwMTJFQUQiLCJ2aXNpdG9yX2lkIjoiMzY2NTU1Nzc4MDY0NDgzNDk4OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 68a44d47215bb1422b2e21b4e4c1e6fd113ec398609607a4578782937a21c18f |
| hovercard-subject-tag | issue:5187253400 |
| 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/70262/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1827dda0a28e794ce8031a344af37cf3fef027df29e0026ba3d4cd2d9578f5f3/angular/angular/issues/70262 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1827dda0a28e794ce8031a344af37cf3fef027df29e0026ba3d4cd2d9578f5f3/angular/angular/issues/70262 |
| og:image:alt | Description @Component() without an explicit changeDetection behaves differently depending on how it's compiled: AOT (production build) → OnPush (the documented default since v22, #67687) JIT (Test... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ValeraGin |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| 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 | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width