Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

ChangeDetectorRef in Pipe used in Input resolves to wrong Components Instance #38883

Closed
nrauschcom opened this issue Sep 17, 2020 · 2 comments
Closed
Labels
freq2: medium regression Indicates than the issue relates to something that worked in a previous version state: confirmed state: has PR type: bug/fix
Milestone

Comments

@nrauschcom
Copy link

nrauschcom commented Sep 17, 2020

馃悶 bug report

Is this a regression?

The same code worked for me in 9.x

Description

I'm using ChangeDetectorRef in one of my Pipes. When used in the Input of a custom Component, CHangeDetectorRef resolves to that component instead of the hosts template.

<hwe-rte-viewer [value]="description$ | async"
  [disabled]="(generalDisabled$ | async) || !([hasPermission$, 'WRITE'] | fnCall | async)"
  (onStartEditing)="onStartEditing($event)"
  (update)="onEditDescription($event)"
  editButtonTooltip="{{'PROPERTIES.GENERAL.DESCRIPTION_EDIT' | translate}}">
</hwe-rte-viewer>

The FnCallPipe gets the folowing ChangeDetectorRef:
image
As you can also see (L156), the code is generated as 傻傻directiveInject(ChangeDetectorRef) instead of 傻傻injectPipeChangeDetectorRef()

馃敩 Minimal Reproduction

https://stackblitz.com/edit/angular-ivy-8x6a4f

You can see, it works with uncompiled code, but not with the included library ngx-function-expression, which uses cdRef exactly like the TestPipe. Thus, the compilation/ngcc process of the library causes this issue.

馃實 Your Environment

Angular Version:

@angular-devkit/architect         0.1001.1
@angular-devkit/build-angular     0.1001.1
@angular-devkit/build-optimizer   0.1001.1
@angular-devkit/build-webpack     0.1001.1
@angular-devkit/core              10.1.1
@angular-devkit/schematics        10.1.1
@angular/cdk                      10.2.0
@angular/flex-layout              9.0.0-beta.31
@angular/material                 10.2.0
@ngtools/webpack                  10.1.1
@schematics/angular               10.1.1
@schematics/update                0.1001.1
rxjs                              6.5.5
typescript                        3.9.7
webpack                           4.43.0

Related Issues

#33677 (closed and fixed)

@nrauschcom nrauschcom changed the title ChangeDetectorRef in Pipe resolves to wrong Component Instance ChangeDetectorRef in Pipe used in Input resolves to wrong Components Instance Sep 17, 2020
@JoostK
Copy link
Member

JoostK commented Sep 17, 2020

Uh oh, I think this broke in #38666 (10.1.1) :(

@JoostK JoostK added comp: ngcc regression Indicates than the issue relates to something that worked in a previous version state: confirmed type: bug/fix labels Sep 17, 2020
@ngbot ngbot bot modified the milestone: needsTriage Sep 17, 2020
@ngbot ngbot bot modified the milestones: needsTriage, Backlog Sep 17, 2020
JoostK added a commit to JoostK/angular that referenced this issue Sep 17, 2020
In angular#38666 we changed how ngcc deals with type expressions, where it
would now always emit the original type expression into the generated
code as a "local" type value reference instead of synthesizing new
imports using an "imported" type value reference. This was done as a fix
to properly deal with renamed symbols, however it turns out that the
compiler has special handling for certain imported symbols, e.g.
`ChangeDetectorRef` from `@angular/core`. The "local" type value
reference prevented this special logic from being hit, resulting in
incorrect compilation of pipe factories.

This commit fixes the issue by manually inspecting the import of the
type expression, in order to return an "imported" type value reference.
By manually inspecting the import we continue to handle renamed symbols.

Fixes angular#38883
mhevery pushed a commit that referenced this issue Sep 18, 2020
#38892)

In #38666 we changed how ngcc deals with type expressions, where it
would now always emit the original type expression into the generated
code as a "local" type value reference instead of synthesizing new
imports using an "imported" type value reference. This was done as a fix
to properly deal with renamed symbols, however it turns out that the
compiler has special handling for certain imported symbols, e.g.
`ChangeDetectorRef` from `@angular/core`. The "local" type value
reference prevented this special logic from being hit, resulting in
incorrect compilation of pipe factories.

This commit fixes the issue by manually inspecting the import of the
type expression, in order to return an "imported" type value reference.
By manually inspecting the import we continue to handle renamed symbols.

Fixes #38883

PR Close #38892
@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 Oct 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
freq2: medium regression Indicates than the issue relates to something that worked in a previous version state: confirmed state: has PR type: bug/fix
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants