You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using DynamicComponent to render custom components inside parsed article content (with Blazor Server prerendering enabled), the component renders outside of surrounding HTML elements like
or
— even though the HTML structure is valid during prerendering (I've checked this with disabled interactive rendering on the page) and verified with MarkupString fragments.
This is a fragment of Article.razor page where article is parsing and rendering. Article is stored in database as html string.
_fragments is the result of article parsing, for example:
<p>This is a test: [[[Link ArticleName="Test"]]]</p>
After parsing this is split into 3 fragments:
<p>This is a test:
"[[[Link ArticleName="Test"]]]" --> rendering as DynamicComponent -> render <a href="..."></a> tag with custom logic
</p>
The resulting prerendered HTML is correct, e.g.:
<p>This is a test:
<ahref="/test">Test</a></p>
But in browser (after hydration), the component renders outside the <p>:
<p>This is a test:</p><ahref="/test">Test</a>
This only happens after hydration in Blazor Server that I'm writing the project
This makes it very difficult to parse HTML+components together safely (e.g. for CMS articles).
This a problem for any tag like
. I have for now two more "markers" [[[...]]] that are parsing and render as proper component, for example video player and it is interactive component. There is no problem with that component because I put the marker for it as just [[[VideoItem Name=".."]]] with no surrounding tags. The thing is some component have to be renders in some surrounding tags for UI experience and proper article styling just as aboe with the link example. For now this to work I use workaround like registered custom elements, but this is not the way to go for SEO purpose.
Expected Behavior
DynamicComponent rendered inline with HTML via parsed fragments should maintain correct DOM hierarchy after hydration, just like during prerendering.
Environment
NET 9
Blazor Server app
Prerendering enabled and Interactive render set on component because of handling complex application state
Visual Studio 2022 preview 5
Suggested Feature / Fix
Adding special configuration in program.cs file setting how fragments are rendering during hydration. (example: warning not unclosed tag)
Consider partial hydration boundaries per component.
Adding by blazor one top surrounding tag during rendering and hydration on render fragment, dynamic component?
Sorry, this is my first filled issue at all. So repro project is put here: https://github.com/witM/BlazorIssue/tree/main/BlazorArticleRender
It used official Blazor template project. See the article page to see what is all about. Here I focused more about functionality than code optimization. I think it is well documented.
javiercn
added
investigate
and removed
Needs: Attention 👋
This issue needs the attention of a contributor, typically because the OP has provided an update.
Needs: Repro
Indicates that the team needs a repro project to continue the investigation on this issue
labels
May 6, 2025
Thanks, for now in my personal project I do some workarounds, but I think the issue I have filled and rendering parsing article related concepts will be in the future a topic in more advanced CMS projects.
When using DynamicComponent to render custom components inside parsed article content (with Blazor Server prerendering enabled), the component renders outside of surrounding HTML elements like
or
This is a fragment of Article.razor page where article is parsing and rendering. Article is stored in database as html string.
_fragments is the result of article parsing, for example:
After parsing this is split into 3 fragments:
<p>This is a test:
<a href="..."></a>
tag with custom logic</p>
The resulting prerendered HTML is correct, e.g.:
But in browser (after hydration), the component renders outside the
<p>
:This a problem for any tag like
You can see all this in action on my website with example article rendering with video component (PL) : https://www.infomaks.pl/post/s_liczby_rzeczywiste/r%C3%B3wnanie_kwadratowe
Expected Behavior
DynamicComponent rendered inline with HTML via parsed fragments should maintain correct DOM hierarchy after hydration, just like during prerendering.
Environment
Suggested Feature / Fix
Repro project
Based on the official blazor template project:
https://github.com/witM/BlazorIssue/tree/main/BlazorArticleRender
See article page to see what's going on.
The text was updated successfully, but these errors were encountered: