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

fix(core): Access injected parent values using SkipSelf #39464

Closed
wants to merge 5 commits into from

Conversation

jessicajaniuk
Copy link
Contributor

@jessicajaniuk jessicajaniuk commented Oct 27, 2020

In ViewEngine, SelfSkip would navigate up the tree to get tokens from
the parent node, skipping the child. This restores that functionality in
Ivy. In ViewEngine, if a special token (e.g. ElementRef) was not found
in the NodeInjector tree, the ModuleInjector was also used to lookup
that token. While special tokens like ElementRef make sense only in a
context of a NodeInjector, we preserved ViewEngine logic for now to
avoid breaking changes.

We identified 4 scenarios related to @SkipSelf and special tokens where
ViewEngine behavior was incorrect and is likely due to bugs. In Ivy this is
implemented to provide a more intuitive API. The list of scenarios can be
found below.

  1. When Injector is used in combination with @Host and @SkipSelf
    on the first Component within a module and the injector is defined in the
    module, ViewEngine will get the injector from the module. In Ivy, it does
    not do this and throws instead. Test

  2. When retrieving a @ViewContainerRef while @SkipSelf and @Host
    are present, in ViewEngine, it throws an exception. In Ivy it returns the host
    ViewContainerRef. Test

  3. When retrieving a @ViewContainerRef on an embedded view and
    @SkipSelf is present, in ViewEngine, the ref is null. In Ivy it returns the
    parent ViewContainerRef. Test

  4. When utilizing viewProviders and providers, a child component that is
    nested within a parent component that has @SkipSelf on a viewProvider
    value, if that provider is provided by the parent component's viewProviders
    and providers, ViewEngine will return that parent's viewProviders value,
    which violates how viewProviders' visibility should work. In Ivy, it retrieves
    the value from providers, as it should. Test

These discrepancies all behave as they should in Ivy and are likely bugs in
ViewEngine.

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.io application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

Currently Ivy ignores @SkipSelf entirely, which deviates from ViewEngine and expectations of behavior.

Issue Number: 34066, 34819

What is the new behavior?

@SkipSelf now properly navigates up the view tree to find the correct injected resource in the parents.

Does this PR introduce a breaking change?

  • Yes
  • No

Closes #34066, #34819.

@google-cla google-cla bot added the cla: yes label Oct 27, 2020
@jessicajaniuk jessicajaniuk added the area: core Issues related to the framework runtime label Oct 27, 2020
@ngbot ngbot bot added this to the needsTriage milestone Oct 27, 2020
Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work @jessicajaniuk 👍 I've left a few comments.

packages/core/src/render3/di.ts Outdated Show resolved Hide resolved
packages/core/src/render3/di.ts Outdated Show resolved Hide resolved
packages/core/src/render3/di.ts Outdated Show resolved Hide resolved
packages/core/src/render3/di.ts Outdated Show resolved Hide resolved
packages/core/src/render3/di.ts Outdated Show resolved Hide resolved
packages/core/src/render3/di.ts Outdated Show resolved Hide resolved
packages/core/src/render3/di.ts Outdated Show resolved Hide resolved
packages/core/src/render3/di.ts Outdated Show resolved Hide resolved
packages/core/src/render3/di.ts Outdated Show resolved Hide resolved
packages/core/test/acceptance/di_spec.ts Outdated Show resolved Hide resolved
packages/core/src/render3/di.ts Outdated Show resolved Hide resolved
packages/core/src/render3/di.ts Outdated Show resolved Hide resolved
packages/core/src/render3/di.ts Outdated Show resolved Hide resolved
packages/core/src/render3/di.ts Outdated Show resolved Hide resolved
packages/core/src/render3/di.ts Outdated Show resolved Hide resolved
@jessicajaniuk jessicajaniuk added the target: patch This PR is targeted for the next patch release label Oct 29, 2020
@jessicajaniuk jessicajaniuk marked this pull request as ready for review October 29, 2020 20:55
@jessicajaniuk jessicajaniuk added the action: review The PR is still awaiting reviews from at least one requested reviewer label Oct 29, 2020
packages/core/test/acceptance/di_spec.ts Show resolved Hide resolved
packages/core/test/acceptance/di_spec.ts Outdated Show resolved Hide resolved
packages/core/test/acceptance/di_spec.ts Outdated Show resolved Hide resolved
packages/core/test/acceptance/di_spec.ts Outdated Show resolved Hide resolved
packages/core/test/acceptance/di_spec.ts Outdated Show resolved Hide resolved
packages/core/test/acceptance/di_spec.ts Outdated Show resolved Hide resolved
packages/core/test/acceptance/di_spec.ts Outdated Show resolved Hide resolved
packages/core/test/acceptance/di_spec.ts Outdated Show resolved Hide resolved
packages/core/test/acceptance/di_spec.ts Outdated Show resolved Hide resolved
packages/core/test/acceptance/di_spec.ts Outdated Show resolved Hide resolved
packages/core/test/acceptance/di_spec.ts Outdated Show resolved Hide resolved
packages/core/test/acceptance/di_spec.ts Show resolved Hide resolved
packages/core/test/acceptance/di_spec.ts Outdated Show resolved Hide resolved
packages/core/test/acceptance/di_spec.ts Outdated Show resolved Hide resolved
packages/core/test/acceptance/di_spec.ts Outdated Show resolved Hide resolved
packages/core/test/acceptance/di_spec.ts Outdated Show resolved Hide resolved
packages/core/test/acceptance/di_spec.ts Outdated Show resolved Hide resolved
packages/core/test/acceptance/di_spec.ts Outdated Show resolved Hide resolved
Copy link
Member

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love all those new tests! Just left a few drive-by comments that you can ignore if you wish.

packages/core/src/render3/di.ts Outdated Show resolved Hide resolved
packages/core/src/render3/di.ts Outdated Show resolved Hide resolved
packages/core/src/render3/di.ts Outdated Show resolved Hide resolved
packages/core/src/render3/di.ts Outdated Show resolved Hide resolved
packages/core/src/render3/di.ts Outdated Show resolved Hide resolved
packages/core/test/acceptance/di_spec.ts Show resolved Hide resolved
packages/core/test/acceptance/di_spec.ts Outdated Show resolved Hide resolved
packages/core/test/acceptance/di_spec.ts Show resolved Hide resolved
packages/core/test/acceptance/di_spec.ts Outdated Show resolved Hide resolved
packages/core/test/acceptance/di_spec.ts Show resolved Hide resolved
Copy link
Member

@JoostK JoostK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a typo in the commit message, which mentions SelfSkip instead of SkipSelf.

packages/core/src/render3/di.ts Outdated Show resolved Hide resolved
packages/core/src/render3/di.ts Outdated Show resolved Hide resolved
packages/core/src/render3/di.ts Outdated Show resolved Hide resolved
@google-cla
Copy link

google-cla bot commented Nov 5, 2020

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@google-cla
Copy link

google-cla bot commented Nov 5, 2020

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@AndrewKushnir
Copy link
Contributor

Presubmit.

Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed-for: size-tracking

@pullapprove pullapprove bot requested a review from alxhub November 5, 2020 22:50
Copy link
Contributor

@atscott atscott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed-for: size-tracking

@AndrewKushnir AndrewKushnir added target: rc This PR is targeted for the next release-candidate and removed target: minor This PR is targeted for the next minor release action: presubmit The PR is in need of a google3 presubmit labels Nov 6, 2020
@jessicajaniuk jessicajaniuk added the action: merge The PR is ready for merge by the caretaker label Nov 6, 2020
mhevery pushed a commit that referenced this pull request Nov 6, 2020
In ViewEngine, SelfSkip would navigate up the tree to get tokens from
the parent node, skipping the child. This restores that functionality in
Ivy. In ViewEngine, if a special token (e.g. ElementRef) was not found
in the NodeInjector tree, the ModuleInjector was also used to lookup
that token. While special tokens like ElementRef make sense only in a
context of a NodeInjector, we preserved ViewEngine logic for now to
avoid breaking changes.

We identified 4 scenarios related to @SkipSelf and special tokens where
ViewEngine behavior was incorrect and is likely due to bugs. In Ivy this
is implemented to provide a more intuitive API. The list of scenarios
can be found below.

1. When Injector is used in combination with @host and @SkipSelf on the
first Component within a module and the injector is defined in the
module, ViewEngine will get the injector from the module. In Ivy, it
does not do this and throws instead.

2. When retrieving a @ViewContainerRef while @SkipSelf and @host are
present, in ViewEngine, it throws an exception. In Ivy it returns the
host ViewContainerRef.

3. When retrieving a @ViewContainerRef on an embedded view and @SkipSelf
is present, in ViewEngine, the ref is null. In Ivy it returns the parent
ViewContainerRef.

4. When utilizing viewProviders and providers, a child component that is
nested within a parent component that has @SkipSelf on a viewProvider
value, if that provider is provided by the parent component's
viewProviders and providers, ViewEngine will return that parent's
viewProviders value, which violates how viewProviders' visibility should
work. In Ivy, it retrieves the value from providers, as it should.

These discrepancies all behave as they should in Ivy and are likely bugs
in ViewEngine.

PR Close #39464
@mhevery mhevery closed this in 290ea57 Nov 6, 2020
@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
@jessicajaniuk jessicajaniuk deleted the skipself branch October 26, 2021 22:06
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: core Issues related to the framework runtime cla: yes target: rc This PR is targeted for the next release-candidate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

In Ivy, SkipSelf() is not accessing the parent's ViewContainerRef, ElementRef, etc
8 participants