Sitelet https://github.com/angular/angular/pull/70261
Skip to content

fix(core): default the Component decorator to OnPush change detection in JIT - #70261

Closed
ValeraGin wants to merge 1 commit into
angular:mainfrom
ValeraGin:fix-jit-component-default-changedetection
Closed

fix(core): default the Component decorator to OnPush change detection in JIT#70261
ValeraGin wants to merge 1 commit into
angular:mainfrom
ValeraGin:fix-jit-component-default-changedetection

Conversation

@ValeraGin

Copy link
Copy Markdown

What's the problem

@Component() compiled in JIT (TestBed, Jest, etc.) still defaults changeDetection to Eager. The AOT compiler already defaults to OnPush — that changed in #67687. So a component with no changeDetection set behaves as OnPush in a real build but as Eager under TestBed. Tests don't exercise the same strategy the app ships with.

Found this while removing "redundant" explicit OnPush from a bunch of components after upgrading to v22 — one test broke, and only in JIT.

Why it's still there

packages/core/src/metadata/directives.ts line 682 was never touched by #67687. It still hardcodes:

(c: Component = {}) => ({changeDetection: ChangeDetectionStrategy.Eager, ...c}),

There's actually a paper trail for this. The very TODO that anticipated the fix:

-  // TODO(jeanmeche): remove the ts-ignore when OnPush is the default
-  // @ts-ignore

was removed in cf3b7fe489, the same day #67687 merged — but only the comment/ts-ignore was removed, not the value it was pointing at. It's been Eager ever since (checked main and the latest published 22.1.2).

The fix

One line: EagerOnPush in the decorator default, plus a regression test asserting getComponentDef(...).onPush for a component with no explicit changeDetection.

I couldn't run the full internal test suite here (no Bazel setup on my end), so this may well surface spec files elsewhere in the repo that quietly relied on the old JIT default — happy to help track those down if CI turns anything up.

… in JIT

The AOT compiler already defaults changeDetection to OnPush for
components that don't specify a strategy (see
compileComponentFromMetadata in packages/compiler/src/render3/view/
compiler.ts, changed in angular#67687). The Component decorator itself,
which is what TestBed/Jest exercise when compiling in JIT mode, was
never updated and still defaults to ChangeDetectionStrategy.Eager.

This means a component with no explicit changeDetection behaves as
OnPush in a production AOT build but as Eager under TestBed, so unit
tests don't exercise the strategy the app actually ships with.

A TODO left by the original OnPush-by-default change anticipated this
follow-up ("remove the ts-ignore when OnPush is the default", commit
cf3b7fe) but was removed the same day without the value itself
being updated.

Added a regression test asserting the JIT-compiled definition's
onPush flag for a component without an explicit changeDetection.
@google-cla

google-cla Bot commented Aug 18, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@pullapprove
pullapprove Bot requested a review from JeanMeche August 18, 2026 23:17
@angular-robot angular-robot Bot added the area: core Issues related to the framework runtime label Aug 18, 2026
@ngbot ngbot Bot added this to the Backlog milestone Aug 18, 2026
@ValeraGin

Copy link
Copy Markdown
Author

Filed as #70262 with a minimal repro.

@SkyZeroZx

Copy link
Copy Markdown
Contributor

This is a duplicate of #69898

@atscott atscott closed this Aug 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: core Issues related to the framework runtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants