Skip to content

Transplanted views are change detected regardless if they're detached from CD when inside OnPush components #46973

Closed

Description

@edusperoni

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:

  1. Find all templates that need to be CDed down the tree
  2. if the component is NOT Dirty or CheckAlways then we start CDing the templates, as long as the template count is > 0
  3. 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

Activity

  1. added this to the needsTriage milestone on Jul 27, 2022
  2. added
    P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
    on Aug 2, 2022
  3. modified the milestones: needsTriage, Backlog on Aug 2, 2022
  4. pkozlowski-opensource commented on Aug 9, 2022

    @pkozlowski-opensource
    Member

    This issue was fixed by #46974

  5. angular-automatic-lock-bot commented on Sep 9, 2022

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  6. locked and limited conversation to collaborators on Sep 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: coreIssues related to the framework runtimecore: change detectionstate: has PR

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions