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] Attributes of HTML custom elements not yet initialized when connectedCallback() is invoked #6218

Closed
ranabuelo opened this issue Jan 2, 2019 · 7 comments · Fixed by #24006
Labels
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
Milestone

Comments

@ranabuelo
Copy link

Custom HTLM elements are usually initialized from the connectedCallback using the attributes from the DOM. Browsers therefore set all attributes at the custom element before the callback gets invoked.

In Blazor, however, element attributes are set after invoking the connectedCallback. This seems to happen in the BrowserRenderer.insertElement function where insertLogicalChild is called before the attributes are actually being applied. Moving the insertLogicalChild() call to the end of the function seems to solve the issue.

Occurred with Blazor 0.7.0.

@Eilon Eilon added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Jan 2, 2019
@danroth27 danroth27 added the area-blazor Includes: Blazor, Razor Components label Feb 6, 2019
@mkArtakMSFT mkArtakMSFT added help wanted Up for grabs. We would accept a PR to help resolve this issue enhancement This issue represents an ask for new feature or an enhancement to an existing one labels Apr 5, 2019
@mkArtakMSFT
Copy link
Member

Thanks for contacting us, @ranabuelo.
This is not something we plan to do in the near future, yet we would happily consider a PR if you'd send one.

@mkArtakMSFT mkArtakMSFT added this to the Backlog milestone Apr 5, 2019
@mkArtakMSFT
Copy link
Member

@ranabuelo could you also share details about what you are trying to do? How would you use such a feature?

@ranabuelo
Copy link
Author

ranabuelo commented Apr 13, 2019

My use cases are straightforward:

  • Use web components from 3rd-party frameworks in Razor Components.
  • Share web components between ASP.Net projects and plain HTML/Javascript projects.

When I used the same custom HTML element in a plain HTML/Javascript project, it worked fine. But it didn't work with Blazor because the connectedCallback was called before attributes have been set by Blazor, whereas in a static HTML context, browsers first set all attributes before invoking the connectedCallback. So right now I consider this to be a bug rather than a feature request...

I'll try to test with a recent preview version and provide a PR for it. Unfortunately, I don't get preview 3 running with VS 2019 because of issue #8384. So I probably need to wait for preview 4.

@mkArtakMSFT mkArtakMSFT removed area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates labels May 9, 2019
@ma499
Copy link

ma499 commented Jul 8, 2019

Did you get a chance to try it out @ranabuelo?

Like you I’m interested in using Web Components within Blazor apps.

@githubfanster
Copy link

i am also interested in similar scenarios as discussed here by @ranabuelo. it would be nice to have blazor playing well with html custom elements

@veikkoeeva
Copy link

veikkoeeva commented Oct 22, 2019

For the reference, some component libraries: https://open-wc.org/faq/component-libraries.html. From the referenced #10170, though this might be achieavable via JS interop -- looks like it -- a good experience with Web APIs and ability to author web components with Blazor would be nice.

Extending to the improbable, but to make this more complete, maybe also doing rendering like lit-html, hyperHTML and other string templating engines are doing (yes, there is RenderTree). Some more consideration to this in the linked #10170.

@jspuij
Copy link
Contributor

jspuij commented Jul 16, 2020

@SteveSandersonMS Picking this one up for the Blazor July sprint.

jspuij added a commit to jspuij/AspNetCore that referenced this issue Jul 17, 2020
@SteveSandersonMS SteveSandersonMS added Done This issue has been fixed and removed help wanted Up for grabs. We would accept a PR to help resolve this issue labels Jul 17, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Aug 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants