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

Restrict parent and child component hierarchy in blazor #12302

Open
Stamo-Gochev opened this issue Jul 18, 2019 · 12 comments
Open

Restrict parent and child component hierarchy in blazor #12302

Stamo-Gochev opened this issue Jul 18, 2019 · 12 comments
Labels
affected-few This issue impacts only small number of customers area-blazor Includes: Blazor, Razor Components component ecosystem Indicates an issue which also has impact on 3rd party component ecosystem Components Big Rock This issue tracks a big effort which can span multiple issues enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-razor.language feature-rendering Features dealing with how blazor renders components Pillar: Complete Blazor Web Priority:2 Work that is important, but not critical for the release severity-major This label is used by an internal tool
Milestone

Comments

@Stamo-Gochev
Copy link

Stamo-Gochev commented Jul 18, 2019

Tag helpers can restrict (to a certain extent) which tags can be their child tag helpers and vice versa using RestrictChildren:

[HtmlTargetElement("parent-taghelper")]
[RestrictChildren("child-taghelper")]
public partial class ParentTagHelper : TagHelper { ... }

and also with ParentTag:

[HtmlTargetElement("child-taghelper", ParentTag="parent-taghelper" )]
public partial class ChildTagHelper : TagHelper { ... }

What will be the way to do that in blazor? Having the ability to restrict parent/child hierarchy will be very important for the IntelliSense as the users of components will not be able to define components in incorrect places.

Describe the solution you'd like

How tag helpers are implemented to solve this issue (using strings) can be improved What I think will be better is to pass the name of the class that can be a parent of child in a way similar to:

[Child(MyNamespace.Components.ChildComponent)]
// multiple children
[Child(MyNamespace.Components.AnotherChildComponent)]
public class ParentComponent: ComponentBase

and the other way around:

[Parent(MyNamespace.Components.ParentComponent)]
// multiple parents
[Parent(MyNamespace.Components.AnotherParentComponent)]
public class ChildComponent : ComponentBase

The exact names of the attributes can be different. I am not sure whether they should be multiple attributes for a list of parents/children or a single one (e.g. [Children(ChildComponent, AnotherChildComponent)]), but the general idea is to use concrete class names instead of strings.

You can also suggest other ways to solve this issue apart from using attributes. What are your thoughts? @SteveSandersonMS @NTaylorMullen

Additional context

I want to point out an analogy with a problem that we faced when building tag helpers that we want to avoid when building blazor components.

The problem that we faced when creating tag helpers using the parent/child restrictions was that when a tag helper with the same name was used in more than one parents, the IntelliSense doesn't display it correctly. Here is an example:

We have the pointer tag helper in both the RadialGauge and LinearGauge tag helpers. As the name "pointer" is not unique, there is a problem like that:

taghelper

Note that although we are in the radial gauge tag helper, the IntelliSense picks up things from the linear gauge.

We discussed with @NTaylorMullen back in the days that the fix for that is to use unique names for the tag helpers, but this clutters the names as it requires a unique prefix before each name on each level (or at least in places of collisions). For longer nesting of hierarchies, which happens in more complex tag helpers, this is getting very long.

Restricting parent/child hierarchy with class names instead of strings should fix this problem (if this approach is chosen by blazor) as class names are unique according to a namespace.

@Stamo-Gochev Stamo-Gochev changed the title Restrict parent and child component hierarchy Restrict parent and child component hierarchy in blazor Jul 18, 2019
@mkArtakMSFT mkArtakMSFT added the area-blazor Includes: Blazor, Razor Components label Jul 18, 2019
@mkArtakMSFT mkArtakMSFT added this to the Backlog milestone Jul 19, 2019
@mkArtakMSFT mkArtakMSFT added the enhancement This issue represents an ask for new feature or an enhancement to an existing one label Jul 19, 2019
@mkArtakMSFT
Copy link
Member

We've moved this issue to the Backlog milestone. This means that it is not going to happen for the coming release. We will reassess the backlog following the current release and consider this item at that time. However, keep in mind that there are many other high priority features with which it will be competing for resources.

@danroth27 danroth27 modified the milestones: Backlog, 5.0.0-preview1 Aug 22, 2019
@danroth27
Copy link
Member

This is an ask from one of the major Blazor component vendors, so let's consider it for 5.0

@danroth27 danroth27 added the component ecosystem Indicates an issue which also has impact on 3rd party component ecosystem label Aug 27, 2019
@Stamo-Gochev
Copy link
Author

Another option that can be discussed is to use an attribute for defining an "inner prop", e.g.:

public class ParentComponent: ComponentBase
{
    [ChildProperty]
    public ChildComponent ChildComponentInstance
    ...
}

By doing this, it is explicit that the ChildComponent should be visible from the IntelliSense when nested directly in the ParentComponent tag.

@mkArtakMSFT mkArtakMSFT added the Components Big Rock This issue tracks a big effort which can span multiple issues label Jan 10, 2020
@SteveSandersonMS SteveSandersonMS added affected-few This issue impacts only small number of customers severity-major This label is used by an internal tool labels Oct 9, 2020 — with ASP.NET Core Issue Ranking
@ghost
Copy link

ghost commented Oct 9, 2020

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@mkArtakMSFT mkArtakMSFT modified the milestones: .NET 8 Planning, Backlog Sep 28, 2022
@dotnet dotnet deleted a comment Sep 28, 2022
@dotnet dotnet deleted a comment Sep 28, 2022
@danroth27 danroth27 modified the milestones: Backlog, .NET 8 Planning Oct 27, 2022
@ghost
Copy link

ghost commented Oct 27, 2022

Thanks for contacting us.

We're moving this issue to the .NET 8 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s).
If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues.
To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

@ghost
Copy link

ghost commented Jun 29, 2023

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@ghost
Copy link

ghost commented Dec 19, 2023

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affected-few This issue impacts only small number of customers area-blazor Includes: Blazor, Razor Components component ecosystem Indicates an issue which also has impact on 3rd party component ecosystem Components Big Rock This issue tracks a big effort which can span multiple issues enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-razor.language feature-rendering Features dealing with how blazor renders components Pillar: Complete Blazor Web Priority:2 Work that is important, but not critical for the release severity-major This label is used by an internal tool
Projects
None yet
Development

No branches or pull requests

10 participants