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

Blazor Server-Side: Render Component via JavaScript #13766

Closed
schmitch opened this issue Sep 6, 2019 · 4 comments
Closed

Blazor Server-Side: Render Component via JavaScript #13766

schmitch opened this issue Sep 6, 2019 · 4 comments
Labels
affected-few This issue impacts only small number of customers area-blazor Includes: Blazor, Razor Components Done This issue has been fixed enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-blazor-server severity-blocking This label is used by an internal tool
Milestone

Comments

@schmitch
Copy link

schmitch commented Sep 6, 2019

Is your feature request related to a problem? Please describe.

Currently if somebody has a big codebase in say react/angular (or other SPA framework) and want to migrate to Blazor Server-Side he would need to rewrite everything at once.
So it would be great if it would be possible to "render" a blazor component server-side via JavaScript methods into a dom element.

Describe the solution you'd like

Probably it would be good enough to have a javascript library published to npm that can call a blazor component by name.
I think the following points would need to be addressed aswell:

  • Input Parameters (how to handle these)
  • Output Events (how to handle these, to interact with other SPAs)
  • Authentication/Authorization (if cookies are used it should work as-is, else also allow to send the auth token?!)
  • manual Blazor Bootstrap, i.e. since the Blazor Server js library would probably need to be bundeled.

something like await Html.RenderComponentAsync<CoursesList>(new { Courses = Model }) just for typescript with more options. Probably also needs some changes to blazor.

I think at the moment it's possible to render to a razor view via RenderMode.Server and innerHTML the generated comment. (get the html page with the comment via ajax)

actually RenderComponentAsync has a protocol that might be useful for the JavaScript part:
https://github.com/aspnet/AspNetCore/blob/v3.0.0-preview9.19424.4/src/Components/Server/src/Circuits/ServerComponentDeserializer.cs unfortunatly it needs DataProtection and I'm also unsure how useful Authentication/Authorization is on these components. Because I tried preview9 and the component will be rendered (but not work) as soon as the marker exists and the RazorPage/Mvc is AllowAnon.

Additional context

Guess it would be a nice addition for .NET 5. And make it easier to test out Blazor when just creating a small set of components.

@pranavkm pranavkm added the area-blazor Includes: Blazor, Razor Components label Sep 6, 2019
@mkArtakMSFT mkArtakMSFT added the enhancement This issue represents an ask for new feature or an enhancement to an existing one label Sep 6, 2019
@mkArtakMSFT mkArtakMSFT added this to the Backlog milestone Sep 6, 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.

@0x53A
Copy link

0x53A commented Jul 24, 2020

Has there been any progress on this?

Not being able to create hostable-from-js components means we would be unable to reuse anything we build in blazor, which kinda kills it for us.

Edit: we are interested in blazor-webassembly, while this issue references blazor-server-side, but I believe the situation there is the same?

@SteveSandersonMS SteveSandersonMS added affected-few This issue impacts only small number of customers severity-blocking This label is used by an internal tool labels Oct 14, 2020 — with ASP.NET Core Issue Ranking
@adamhathcock
Copy link

I would love to be able to reuse the Blazor server JavaScript snippet outside of CSHTML.

This would enable migration from other SPAs to Blazor in a better slice approach. Otherwise I have to resort to something like iframes in my angular app and post messages across.

I keep thinking this must be possible as the rendered CSHTML output is just JavaScript. Understanding how I could do this myself or why it isn't possible would be great.

Thanks!

@javiercn
Copy link
Member

javiercn commented Nov 4, 2021

We implemented this feature as part of our 6.0 wave. You can see more details here

@javiercn javiercn closed this as completed Nov 4, 2021
@javiercn javiercn added the Done This issue has been fixed label Nov 4, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Dec 4, 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 Done This issue has been fixed enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-blazor-server severity-blocking This label is used by an internal tool
Projects
None yet
Development

No branches or pull requests

7 participants