Skip to content

Angular/elements OnPush input changes does not trigger change detection #38948

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
artaommahe opened this issue Sep 23, 2020 · 3 comments
Closed
Labels
area: elements Issues related to Angular Elements P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent state: confirmed type: bug/fix
Milestone

Comments

@artaommahe
Copy link
Contributor

artaommahe commented Sep 23, 2020

🐞 bug report

Affected Package

The issue is caused by package @angular/elements

Is this a regression?

dunno

Description

  • create custom elements via @angular/elements from component with input and changeDetection: ChangeDetectionStrategy.OnPush
  • set it's initial input value from the application or change it
  • component's CD is not triggered, template is not updated

🔬 Minimal Reproduction

Clone https://github.com/artaommahe/Angular-elements-input-update. There are two applications: widgets with custom element and main-app with custom element usage in other angular app.

Two ways to face the issue - from main-app or from plain js custom element usage.

Plain js

platform's code here https://github.com/artaommahe/Angular-elements-input-update/blob/master/projects/widgets/src/index.html#L11

Other angular app

platform's code here https://github.com/artaommahe/Angular-elements-input-update/blob/master/projects/main-app/src/app/app.component.ts#L6

or you can remove ChangeDetectionStrategy.OnPush in some-widget component and everything will work too

🔥 Exception or Error

🌍 Your Environment

Angular Version:


PS D:\projects\issues\angular-elements-input-update> yarn ng version                                                                  
yarn run v1.16.0
$ ng version

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    

Angular CLI: 10.1.2
Node: 12.18.1
OS: win32 x64

Angular: 10.1.2
... animations, cli, common, compiler, compiler-cli, core
... elements, forms, platform-browser, platform-browser-dynamic
... router
Ivy Workspace: Yes

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1001.2
@angular-devkit/build-angular   0.1001.2
@angular-devkit/core            10.1.2
@angular-devkit/schematics      10.1.2
@schematics/angular             10.1.2
@schematics/update              0.1001.2
rxjs                            6.6.3
typescript                      4.0.3

Anything else relevant?

@AndrewKushnir AndrewKushnir added the area: elements Issues related to Angular Elements label Sep 23, 2020
@ngbot ngbot bot added this to the needsTriage milestone Sep 23, 2020
@gkalpak gkalpak added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent state: confirmed type: bug/fix labels Oct 23, 2020
@ngbot ngbot bot modified the milestones: needsTriage, Backlog Oct 23, 2020
@gkalpak
Copy link
Member

gkalpak commented Oct 23, 2020

I can confirm this still happens with v10.2.0. Here is a StackBlitz reproduction.
I need to do some more digging to understand why it happens 😁

gkalpak added a commit to gkalpak/angular that referenced this issue Oct 27, 2020

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
…hange

As with regular Angular components, Angular elements are expected to
have their views update when inputs change.

Previously, Angular Elements views where not update if the underlying
component used the `OnPush` change detection strategy.

This commit fixes this by calling `markForCheck()` on the component
view's `ChangeDetectorRef`.

NOTE:
This is similar to how `@angular/upgrade` does it:
https://github.com/angular/angular/blob/3236ae0ee118d0734c90fa9f3767435396213470/packages/upgrade/src/common/src/downgrade_component_adapter.ts#L146.

Fixes angular#38948
gkalpak added a commit to gkalpak/angular that referenced this issue Oct 27, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
…hange

As with regular Angular components, Angular elements are expected to
have their views update when inputs change.

Previously, Angular Elements views where not update if the underlying
component used the `OnPush` change detection strategy.

This commit fixes this by calling `markForCheck()` on the component
view's `ChangeDetectorRef`.

NOTE:
This is similar to how `@angular/upgrade` does it:
https://github.com/angular/angular/blob/3236ae0ee118d0734c90fa9f3767435396213470/packages/upgrade/src/common/src/downgrade_component_adapter.ts#L146.

Fixes angular#38948
@gkalpak
Copy link
Member

gkalpak commented Oct 27, 2020

I have created #39452, although I am not sure it is the best way to fix it 😅

gkalpak added a commit to gkalpak/angular that referenced this issue Oct 27, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
…hange

As with regular Angular components, Angular elements are expected to
have their views update when inputs change.

Previously, Angular Elements views where not update if the underlying
component used the `OnPush` change detection strategy.

This commit fixes this by calling `markForCheck()` on the component
view's `ChangeDetectorRef`.

NOTE:
This is similar to how `@angular/upgrade` does it:
https://github.com/angular/angular/blob/3236ae0ee118d0734c90fa9f3767435396213470/packages/upgrade/src/common/src/downgrade_component_adapter.ts#L146.

Fixes angular#38948
gkalpak added a commit to gkalpak/angular that referenced this issue Oct 27, 2020
…hange

As with regular Angular components, Angular elements are expected to
have their views update when inputs change.

Previously, Angular Elements views were not updated if the underlying
component used the `OnPush` change detection strategy.

This commit fixes this by calling `markForCheck()` on the component
view's `ChangeDetectorRef`.

NOTE:
This is similar to how `@angular/upgrade` does it:
https://github.com/angular/angular/blob/3236ae0ee118d0734c90fa9f3767435396213470/packages/upgrade/src/common/src/downgrade_component_adapter.ts#L146.

Fixes angular#38948
gkalpak added a commit to gkalpak/angular that referenced this issue Oct 28, 2020
…hange

As with regular Angular components, Angular elements are expected to
have their views update when inputs change.

Previously, Angular Elements views were not updated if the underlying
component used the `OnPush` change detection strategy.

This commit fixes this by calling `markForCheck()` on the component
view's `ChangeDetectorRef`.

NOTE:
This is similar to how `@angular/upgrade` does it:
https://github.com/angular/angular/blob/3236ae0ee118d0734c90fa9f3767435396213470/packages/upgrade/src/common/src/downgrade_component_adapter.ts#L146.

Fixes angular#38948
gkalpak added a commit to gkalpak/angular that referenced this issue Nov 4, 2020
…hange

As with regular Angular components, Angular elements are expected to
have their views update when inputs change.

Previously, Angular Elements views were not updated if the underlying
component used the `OnPush` change detection strategy.

This commit fixes this by calling `markForCheck()` on the component
view's `ChangeDetectorRef`.

NOTE:
This is similar to how `@angular/upgrade` does it:
https://github.com/angular/angular/blob/3236ae0ee118d0734c90fa9f3767435396213470/packages/upgrade/src/common/src/downgrade_component_adapter.ts#L146.

Fixes angular#38948
gkalpak added a commit to gkalpak/angular that referenced this issue Nov 4, 2020
…hange

As with regular Angular components, Angular elements are expected to
have their views update when inputs change.

Previously, Angular Elements views were not updated if the underlying
component used the `OnPush` change detection strategy.

This commit fixes this by calling `markForCheck()` on the component
view's `ChangeDetectorRef`.

NOTE:
This is similar to how `@angular/upgrade` does it:
https://github.com/angular/angular/blob/3236ae0ee118d0734c90fa9f3767435396213470/packages/upgrade/src/common/src/downgrade_component_adapter.ts#L146.

Fixes angular#38948
mhevery pushed a commit that referenced this issue Nov 6, 2020
…hange (#39452)

As with regular Angular components, Angular elements are expected to
have their views update when inputs change.

Previously, Angular Elements views were not updated if the underlying
component used the `OnPush` change detection strategy.

This commit fixes this by calling `markForCheck()` on the component
view's `ChangeDetectorRef`.

NOTE:
This is similar to how `@angular/upgrade` does it:
https://github.com/angular/angular/blob/3236ae0ee118d0734c90fa9f3767435396213470/packages/upgrade/src/common/src/downgrade_component_adapter.ts#L146.

Fixes #38948

PR Close #39452
@mhevery mhevery closed this as completed in bdce769 Nov 6, 2020
gkalpak added a commit to gkalpak/angular that referenced this issue Nov 7, 2020
…hange (angular#39452)

As with regular Angular components, Angular elements are expected to
have their views update when inputs change.

Previously, Angular Elements views were not updated if the underlying
component used the `OnPush` change detection strategy.

This commit fixes this by calling `markForCheck()` on the component
view's `ChangeDetectorRef`.

NOTE:
This is similar to how `@angular/upgrade` does it:
https://github.com/angular/angular/blob/3236ae0ee118d0734c90fa9f3767435396213470/packages/upgrade/src/common/src/downgrade_component_adapter.ts#L146.

Fixes angular#38948

PR Close angular#39452
gkalpak added a commit to gkalpak/angular that referenced this issue Nov 7, 2020
…hange (angular#39452)

As with regular Angular components, Angular elements are expected to
have their views update when inputs change.

Previously, Angular Elements views were not updated if the underlying
component used the `OnPush` change detection strategy.

This commit fixes this by calling `markForCheck()` on the component
view's `ChangeDetectorRef`.

NOTE:
This is similar to how `@angular/upgrade` does it:
https://github.com/angular/angular/blob/3236ae0ee118d0734c90fa9f3767435396213470/packages/upgrade/src/common/src/downgrade_component_adapter.ts#L146.

Fixes angular#38948

PR Close angular#39452
@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Dec 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: elements Issues related to Angular Elements P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent state: confirmed type: bug/fix
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants