angular
angular copied to clipboard
Transplanted views are change detected regardless if they're detached from CD when inside OnPush components
Which @angular/* package(s) are the source of the bug?
core
Is this a regression?
No
Description
This is possibly a regression from ivy.
When you create an embedded view and detach it, angular will run CD in it as long as it's inside a OnPush component and it has at least one attached template.
This happens because we do:
- Find all templates that need to be CDed down the tree
- if the component is NOT Dirty or CheckAlways then we start CDing the templates, as long as the template count is > 0
- We never check if the template is attached once we reach this step. So if you have 2 transplanted views the TRANSPLANTED_VIEWS_COUNT will be 2 and both views will be CDed
Please provide a link to a minimal reproduction of the bug
https://stackblitz.com/edit/angular-ivy-mki9ct?file=src%2Fapp%2Fbug.ts,src%2Fapp%2Fapp.module.ts,src%2Fapp%2Fapp.component.html,src%2Fapp%2Fapp.component.ts
Please provide the exception or error you saw
Run the provided example.
Notice that `defaultDetached` is the only one that will be kept stable.
Please provide the environment you discovered this bug in (run ng version)
Angular CLI: 14.1.0
Node: 16.13.2
Package Manager: npm 8.4.1
OS: darwin arm64
Angular: 14.1.0
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1401.0
@angular-devkit/build-angular 14.1.0
@angular-devkit/core 14.1.0
@angular-devkit/schematics 14.1.0
@schematics/angular 14.1.0
rxjs 7.5.6
typescript 4.7.4
Anything else?
No response