Skip to content

refactor(tree): avoid improper query usage #16540

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

Merged
merged 1 commit into from
Jul 19, 2019

Conversation

crisbeto
Copy link
Member

@crisbeto crisbeto commented Jul 16, 2019

The way things are set up at the moment we have a CdkNestedTreeNode which uses a ContentChildren to find a CdkTreeNodeOutlet so that it knows where to render its content. On top of this we have a MatNestedTreeNode which extends CdkNestedTreeNode and defines it's own query at the same property, but looking for a MatTreeNodeOutlet. With this setup it means that both CdkNestedTreeNode and MatNestedTreeNode are trying to write to the same nodeOutlet property and it's by pure coincidence that it works. This is very fragile and it isn't guaranteed to work in future versions of the framework.

These changes fix the issue by removing the query from the MatNestedTreeNode and providing the MatTreeNodeOutlet as a CdkTreeNodeOutlet so that the query on the CdkNestedTreeNode can pick it up.

cc @pkozlowski-opensource

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Jul 16, 2019
@crisbeto crisbeto force-pushed the tree-query-refactor branch from 4eb9921 to 7086935 Compare July 16, 2019 19:22
@crisbeto crisbeto added P2 The issue is important to a large percentage of users, with a workaround target: patch This PR is targeted for the next patch release labels Jul 16, 2019
@crisbeto crisbeto marked this pull request as ready for review July 16, 2019 19:37
@crisbeto crisbeto force-pushed the tree-query-refactor branch from 7086935 to 2092d2b Compare July 16, 2019 20:31
Copy link
Contributor

@Splaktar Splaktar left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

LGTM

@jelbourn jelbourn added pr: lgtm action: merge The PR is ready for merge by the caretaker labels Jul 16, 2019
@jelbourn jelbourn removed the action: merge The PR is ready for merge by the caretaker label Jul 18, 2019
@jelbourn
Copy link
Member

Copying from slack:

A bunch of targets are failing in Google on this because:

  • MatNestedTreeNode extends a mixin
  • In AoT, Angular will ignore mixins since it can't evaluate them, so it doesn't inherent the
    @ContentChildren from the CdkNextedTreeNode (edited)
  • I confirmed that repeating the @ContentChildren in MatNestedTreeNode fixes it (at least in the tests where I was looking), but I don't know if that's still an issue with Ivy
  • The alternate solution would be to stop using the mixin there for now

@crisbeto crisbeto force-pushed the tree-query-refactor branch from 2092d2b to fba7973 Compare July 18, 2019 18:42
The way things are set up at the moment we have a `CdkNestedTreeNode` which uses a `ContentChildren` to find a `CdkTreeNodeOutlet` so that it knows where to render its content. On top of this we have a `MatNestedTreeNode` which extends `CdkNestedTreeNode` and defines it's own query at the same property, but looking for a `MatTreeNodeOutlet`. With this setup it means that both `CdkNestedTreeNode` and `MatNestedTreeNode` are trying to write to the same `nodeOutlet` property and it's by pure coincidence that it works. This is very fragile and it isn't guaranteed to work in future versions of the framework.

These changes fix the issue by removing the query from the `MatNestedTreeNode` and providing the `MatTreeNodeOutlet` as a `CdkTreeNodeOutlet` so that the query on the `CdkNestedTreeNode` can pick it up.
@crisbeto crisbeto force-pushed the tree-query-refactor branch from fba7973 to cf4f46c Compare July 18, 2019 18:48
@crisbeto
Copy link
Member Author

Updated to remove the mixin class.

@crisbeto crisbeto added the action: merge The PR is ready for merge by the caretaker label Jul 18, 2019
@jelbourn jelbourn merged commit 23f71cc into angular:master Jul 19, 2019
andrewseguin pushed a commit that referenced this pull request Jul 29, 2019
The way things are set up at the moment we have a `CdkNestedTreeNode` which uses a `ContentChildren` to find a `CdkTreeNodeOutlet` so that it knows where to render its content. On top of this we have a `MatNestedTreeNode` which extends `CdkNestedTreeNode` and defines it's own query at the same property, but looking for a `MatTreeNodeOutlet`. With this setup it means that both `CdkNestedTreeNode` and `MatNestedTreeNode` are trying to write to the same `nodeOutlet` property and it's by pure coincidence that it works. This is very fragile and it isn't guaranteed to work in future versions of the framework.

These changes fix the issue by removing the query from the `MatNestedTreeNode` and providing the `MatTreeNodeOutlet` as a `CdkTreeNodeOutlet` so that the query on the `CdkNestedTreeNode` can pick it up.
@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 Sep 11, 2019
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 cla: yes PR author has agreed to Google's Contributor License Agreement P2 The issue is important to a large percentage of users, with a workaround target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants