-
Notifications
You must be signed in to change notification settings - Fork 10k
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
Easily passing RenderFragment children to Microsoft.AspNetCore.Mvc.TagHelpers.ComponentTagHelper #31772
Comments
@GitGangGuy thanks for contacting us. We don't support this because it's not obvious to make it work in the general case. A few examples:
The only case where its applicable to do this is when the render mode is static, which is the only mode that can guarantee that we don't try to serialize anything. We haven't seen a huge demand for it, so I'm going to park this in the backlog to gather more feedback about it. |
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. |
@javiercn What is the difference between writing a function that returns the RenderFragment and passing that as a parameter to the |
@GitGangGuy We don't prevent you from passing it as a parameter, however you need to go out of your way to do so. Passing non serializable parameters is not supported, we simply don't put additional code to enforce it because you are going to get an error already in any other cases other than |
@javiercn Why do component arguments in Razor Pages need to be serializable then? The template |
@GitGangGuy parameters are serialized into the document and then sent back to the server when the browser starts the circuit. |
The callback that you pass in during _Host.cshtml needs to get serialized into the document and then sent back to the server when the signalr connection is established and the circuit is started. Delegates are not serializable, hence why this is not allowed. |
We're tracking this as part of #6348 |
Summary
Currently, the
Microsoft.AspNetCore.Mvc.TagHelpers.ComponentTagHelper
/component
tag helper doesn't provide for children (to pass through to RenderFragment properties of the specified component):This throws an error; apparently, this tag helper cannot contain children (
Element does not allow content and cannot have have separate end tag
). After some trying, I came to this:While this works, it is not very asthetically pleasing. I'd like to propose that the
component
tag helper should get support for child components, just as if it were the actual component itself.Motivation and goals
In scope
As outlined above :) I'm proposing a design change to the
Microsoft.AspNetCore.Mvc.TagHelpers.ComponentTagHelper
tag helper, in order to allow children forRenderFragment
props.Risks / unknowns
Developers might accidentally pass in children to components that don't accept RenderFragments, or too little children. As such, some kind of typing/validation is needed to ensure that, just like with a regular component, all the property requirements are ordinarily met.
Examples
See my first code snippet, which outlines the ideal syntax I'm advocating for.
The text was updated successfully, but these errors were encountered: