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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In Ivy, pipes uses providers from a host component where ViewEngine did not #36146

Closed
EmaGht opened this issue Mar 19, 2020 · 8 comments
Closed
Assignees
Labels
area: core Issues related to the framework runtime core: di core: pipes freq1: low regression Indicates than the issue relates to something that worked in a previous version state: has PR type: bug/fix
Milestone

Comments

@EmaGht
Copy link

EmaGht commented Mar 19, 2020

🐞 bug report

Affected Package

@angular/core

Is this a regression?

Yes, works without ivy

Description

I think it's related to this #34227 but i'm not really sure.
What i have is a component let's say component1 that passes an Input to another component component2 and component2shows it as-is.
The problem is that this input gets transformed by a pipe that retrieves via injector the informations to transform this Input. This informations is stored component-wise. component2 also provides it, but for his own data.
Unfortunately, the pipe in question, used in the template of component1 ends up using the dependency declared in component2, probably because the execution gets delegated after change detection has been run, therefore the context of the pipe changes

I'm not honestly sure my English is good enough to explain this properly but luckily i have a repro

🔬 Minimal Reproduction

repo: https://github.com/EmaGht/ivypipe
ng-run version: https://ng-run.com/edit/32k314W605UdYOdVEPCE
Steps:
git clone https://github.com/EmaGht/ivypipe.git
cd ivypipe
npm install
ng serve
check out the on-screen debug informations

For now i think i can work around it telling the pipe explicitly which context should be used but... meh

@AndrewKushnir AndrewKushnir added area: core Issues related to the framework runtime comp: ivy labels Mar 19, 2020
@ngbot ngbot bot added this to the needsTriage milestone Mar 19, 2020
@pkozlowski-opensource
Copy link
Member

Thnx for reporting the issue and providing the reproduce scenario! We will look into this one but if you want to speed up things and help us investigate, providing a minimal, runnable reproduce scenario with https://ng-run.com/ would help immensely!

@EmaGht
Copy link
Author

EmaGht commented Mar 20, 2020

Sure thing, here you go:

https://ng-run.com/edit/32k314W605UdYOdVEPCE

@JoostK
Copy link
Member

JoostK commented Mar 20, 2020

I briefly looked into this and found that the pipe in Ivy is able to see providers of the host component app-component-child, unlike ViewEngine where this was not the case.

There's no static inputs going here, as a pipe can only be present in a a dynamic binding. I'll update the title to this effect.

@JoostK JoostK added core: di core: pipes freq1: low regression Indicates than the issue relates to something that worked in a previous version type: bug/fix labels Mar 20, 2020
@ngbot ngbot bot modified the milestones: needsTriage, Backlog Mar 20, 2020
@JoostK JoostK changed the title Ivy Static Input handling, but with pipes! In Ivy, pipes uses providers from a host component where ViewEngine did not Mar 20, 2020
@JoostK
Copy link
Member

JoostK commented Mar 20, 2020

Tracking in FW-2012

crisbeto added a commit to crisbeto/angular that referenced this issue Apr 4, 2020
…n a component input

Given a structure of `<parent><child [input]="value | pipe"></child></parent>` the injector that is associated with the pipe will inject as if it's placed inside of the `child` component. The issue comes from the fact that we don't have a `TNode` tied to pipe instances and the current `TNode` points to the `child`.

These changes work around the issue by having a flag that indicates whether we're currently "inside of" a pipe, and if we are, DI is essentially treated as if it has `SkipSelf`.

Fixes angular#36146.
crisbeto added a commit to crisbeto/angular that referenced this issue Apr 4, 2020
…n a component input

Given a structure of `<parent><child [input]="value | pipe"></child></parent>` the injector that is associated with the pipe will inject as if it's placed inside of the `child` component. The issue comes from the fact that we don't have a `TNode` tied to pipe instances and the current `TNode` points to the `child`.

These changes work around the issue by having a flag that indicates whether we're currently "inside of" a pipe, and if we are, DI is essentially treated as if it has `SkipSelf`.

Fixes angular#36146.
@crisbeto crisbeto self-assigned this Apr 4, 2020
crisbeto added a commit to crisbeto/angular that referenced this issue Apr 8, 2020
…t node

The flag that determines whether something should be able to inject from `viewProviders` is opt-out and the pipes weren't opted out, resulting in them being able to see the `viewProviders` if they're placed on a component host node.

Fixes angular#36146.
crisbeto added a commit to crisbeto/angular that referenced this issue Apr 8, 2020
…t node

The flag that determines whether something should be able to inject from `viewProviders` is opt-out and the pipes weren't opted out, resulting in them being able to see the `viewProviders` if they're placed on a component host node.

Fixes angular#36146.
crisbeto added a commit to crisbeto/angular that referenced this issue Apr 8, 2020
…t node

The flag that determines whether something should be able to inject from `viewProviders` is opt-out and the pipes weren't opted out, resulting in them being able to see the `viewProviders` if they're placed on a component host node.

Fixes angular#36146.
crisbeto added a commit to crisbeto/angular that referenced this issue Apr 8, 2020
…t node

The flag that determines whether something should be able to inject from `viewProviders` is opt-out and the pipes weren't opted out, resulting in them being able to see the `viewProviders` if they're placed on a component host node.

Fixes angular#36146.
crisbeto added a commit to crisbeto/angular that referenced this issue Apr 17, 2020
…t node

The flag that determines whether something should be able to inject from `viewProviders` is opt-out and the pipes weren't opted out, resulting in them being able to see the viewProviders if they're placed on a component host node.

Fixes angular#36146.
crisbeto added a commit to crisbeto/angular that referenced this issue Apr 17, 2020
…t node

The flag that determines whether something should be able to inject from `viewProviders` is opt-out and the pipes weren't opted out, resulting in them being able to see the viewProviders if they're placed on a component host node.

Fixes angular#36146.
@matsko matsko closed this as completed in 81d23b3 Apr 17, 2020
matsko pushed a commit that referenced this issue Apr 17, 2020
…t node (#36512)

The flag that determines whether something should be able to inject from `viewProviders` is opt-out and the pipes weren't opted out, resulting in them being able to see the viewProviders if they're placed on a component host node.

Fixes #36146.

PR Close #36512
@EmaGht
Copy link
Author

EmaGht commented May 4, 2020

@JoostK
I've tried updating all the packages in my example project but this issue doesn't seem to be fixed...
Updating the ng-run version seems impossible (it gets stuck on "generating preview" for literally days), but updating the github repository and serving it yields the same results as before

@crisbeto
Copy link
Member

crisbeto commented May 4, 2020

The fix for your case, after the changes have been applied, is to switch from providers to viewProviders.

@EmaGht
Copy link
Author

EmaGht commented May 4, 2020

The fix for your case, after the changes have been applied, is to switch from providers to viewProviders.

Ok, can confirm it works using viewProviders instead of providers. Thanks!

Edit: To be honest, it feels very strange to use viewProviders in Ivy when just providers in VE did the trick, but hey... as long as it works

@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 Jun 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: core Issues related to the framework runtime core: di core: pipes freq1: low regression Indicates than the issue relates to something that worked in a previous version state: has PR type: bug/fix
Projects
None yet
5 participants