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

Dynamically added root components #27574

Closed
Tracked by #27883
javiercn opened this issue Nov 6, 2020 · 20 comments
Closed
Tracked by #27883

Dynamically added root components #27574

javiercn opened this issue Nov 6, 2020 · 20 comments
Assignees
Labels
affected-few This issue impacts only small number of customers area-blazor Includes: Blazor, Razor Components design-proposal This issue represents a design proposal for a different issue, linked in the description Done This issue has been fixed enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-blazor-boot-up feature-blazor-component-model Any feature that affects the component model for Blazor (Parameters, Rendering, Lifecycle, etc) severity-blocking This label is used by an internal tool User Story A single user-facing feature. Can be grouped under an epic.
Milestone

Comments

@javiercn
Copy link
Member

javiercn commented Nov 6, 2020

Summary

Support rendering components dynamically after a blazor server or blazor webassembly application has started.

Motivation and goals

We want to improve the way you can add interactivity to an asp.net Core MVC or razor pages application by enabling components to be rendered directly from within JavaScript/HTML intead of just when the app has started.

This enables scenarios where an MVC application that is using JavaScript to add interactivity when an element is added to the dom, can instead leverage Blazor to implement the functionality associated with that component, enabling combining Blazor with existing JavaScript code in a mix and match fashion.

In scope

  • Provide a set of APIs available through JavaScript that enable application authors to create new component instances on Blazor Webassembly and Blazor server.
  • Enable passing parameters to a component from JavaScript

Out of scope

  • Children content within a component. This is more complicated and would like want to take it out of the inital version and add support for it based on feedback.

Risks / unknowns

For server side Blazor there are security implications to this feature that we need to account for, like a limit on the number of components that can be rendered at any time or the list of components that can be rendered as well as their parameters.

Examples

Blazor.renderComponent(element, { componentName: "ShoppingCart" }, parameters: { shoppingCartId: "asdf" });
<shoppint-cart shopping-cart-id="asdf" />
@javiercn javiercn added design-proposal This issue represents a design proposal for a different issue, linked in the description area-blazor Includes: Blazor, Razor Components labels Nov 6, 2020
@captainsafia captainsafia added this to the Next sprint planning milestone Nov 9, 2020
@ghost
Copy link

ghost commented Nov 9, 2020

Thanks for contacting us.
We're moving this issue to the Next sprint planning milestone for future evaluation / consideration. We will evaluate the request when we are planning the work for the next milestone. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

@captainsafia captainsafia added the enhancement This issue represents an ask for new feature or an enhancement to an existing one label Nov 9, 2020
@SteveSandersonMS SteveSandersonMS changed the title Dynamically rendered components Dynamically added root components Jan 26, 2021
@SteveSandersonMS SteveSandersonMS added affected-few This issue impacts only small number of customers severity-blocking This label is used by an internal tool labels Jan 26, 2021 — with ASP.NET Core Issue Ranking
@mkArtakMSFT mkArtakMSFT added the User Story A single user-facing feature. Can be grouped under an epic. label Jan 31, 2021
@amdav
Copy link

amdav commented Mar 17, 2021

I thought it worth commenting that I have been using something similar in production for about 12-months with much success. I am happy to share my learnings and/or code. My focus was doing this from any normal web page (including html pages or asp.net web forms, etc).

I have a "RemoteBlazor" library that just needs to be referenced, and CORS enabled to turn the feature on. Then I use the component on a site such as "test-site.com" and use javascript to load the blazor server component from Azure, such as from "test-components.azurewebsites.net".

I have implemented the ability to:

  • Hook up javascript callbacks so the blazor component just uses EventCallback but the javascript code can be hooked up to that callback.
  • Ability to set properties on the component from javascript.
  • Settings properties, or wiring up events has been implemented by passing javascript objects (so I handle the serialization), rather than strings, so it is a clean API. I use the usual type converters, etc (but it is not perfect yet).

I also implemented a ResourceLoader component that makes it easy to inject scripts and stylesheets into the page hosting the remote blazor component (the kind of stuff you would have placed in your .cshtml hosting page if hosting via razor).

The only reason I have not shared this yet is because I am a little embarrassed by the same security issues you allude to above. I really need to define a way to register which components are exposed; or have attributes that need to be added to components if you want them (or certain properties) exposed on the javascript side.

Something I don't want to do - because I don't use web forms anymore (but somebody should): Implement a web forms hook where setting of parameters can be signed (on the web forms side), and verified on the blazor server side, to allow secure setting of parameters between a web forms app, and the blazor server app. This would be similar to how you initialize a component from a razor page, but done from a web forms page (where the actual blazor server component is remotely hosted)

Let me know if anyone on the team wants further information. Also understand you should be thinking more broadly than just adding these features to razor.cshtml pages.
Regards,
David

@javiercn
Copy link
Member Author

A similar request #26425

@ghost
Copy link

ghost commented Mar 25, 2021

Thanks for contacting us.
We're moving this issue to the Next sprint planning milestone for future evaluation / consideration. We will evaluate the request when we are planning the work for the next milestone. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

FlukeFan added a commit to FlukeFan/MfePoc that referenced this issue Apr 6, 2021
@adamhathcock
Copy link

Is this similar to #13766 ? I think the wording makes it sound like if this work is done then I can render a blazor server component via Javascript dynamically.

@javiercn
Copy link
Member Author

javiercn commented Apr 9, 2021

@adamhathcock if we decide to implement it for server side blazor. There are additional security concerns that we need to address in that case. However, we take note of your interest on having it support SSB

@adamhathcock
Copy link

Thanks for letting me know.

My desire is ported a back office Angular LOB app to Blazor in a piecemeal fashion. SSB is better suited to the use-case I think but even looking to embed WASM controls would be a win for me I think.

Looking forward to this.

@javiercn
Copy link
Member Author

javiercn commented Apr 9, 2021

@adamhathcock can you upvote the top first comment? It helps our tooling do a better job at capturing the interest.

@Xyncgas
Copy link

Xyncgas commented Apr 12, 2021

Thanks for the works I love you people, GIVE ME FIVE !

@Xyncgas
Copy link

Xyncgas commented Apr 12, 2021

I am really excited for this feature, this just makes me think about it again how much convinience I've gotten for .net and the things I am able to do, you guys are good at what you are doing and I appreciate it.

@RChrisCoble
Copy link

RChrisCoble commented Jun 23, 2021

Really hope this behavior makes it into .Net 6 capacity permitting. This would make Blazor far more palatable in a larger development organization that primarily uses Angular. Right now the argument is, "If you do that in Blazor you can't use it anywhere else".

If I have to hear that for the entirety of 2022 I will [cries in Blazor].

@RChrisCoble
Copy link

SteveSandersonMS assigned SteveSandersonMS

No sweeter words were ever read. :)

@RChrisCoble
Copy link

@SteveSandersonMS just to put an extremely fine point on this feature. This will allow hosting Blazor components inside of an Angular application, correct?

@SteveSandersonMS
Copy link
Member

SteveSandersonMS commented Jul 8, 2021

@RChrisCoble That’s certainly the intention!

It should make the inclusion of a Blazor component equivalent to including any other arbitrary web component. To what extent other frameworks like Angular/React/Vue behave well with that is of course up to them, but in general I expect good results.

@SteveSandersonMS
Copy link
Member

Done

@ghost ghost added Done This issue has been fixed and removed Working labels Jul 26, 2021
@RChrisCoble
Copy link

Well that was fast @SteveSandersonMS ! Any idea when we'll get to kick the wheels on this feature?

@boukenka
Copy link

@RChrisCoble According to the milestone, it should be for RC1, which is scheduled for 14 September 2021.

@RChrisCoble
Copy link

But that's like 4,320,000,000 milliseconds away, an eternity in computer time!

@ghost ghost locked as resolved and limited conversation to collaborators Aug 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affected-few This issue impacts only small number of customers area-blazor Includes: Blazor, Razor Components design-proposal This issue represents a design proposal for a different issue, linked in the description Done This issue has been fixed enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-blazor-boot-up feature-blazor-component-model Any feature that affects the component model for Blazor (Parameters, Rendering, Lifecycle, etc) severity-blocking This label is used by an internal tool User Story A single user-facing feature. Can be grouped under an epic.
Projects
None yet
Development

No branches or pull requests