Skip to content

Blazor messes up standard HTMLTemplateElement <template>#67660

Open
Vinoth2562000 wants to merge 2 commits into
dotnet:mainfrom
Vinoth2562000:template-50831
Open

Blazor messes up standard HTMLTemplateElement <template>#67660
Vinoth2562000 wants to merge 2 commits into
dotnet:mainfrom
Vinoth2562000:template-50831

Conversation

@Vinoth2562000

@Vinoth2562000 Vinoth2562000 commented Jul 8, 2026

Copy link
Copy Markdown

Blazor messes up standard HTMLTemplateElement <template>

Description

When content was rendered inside a <template> tag (for example, through a RenderFragment), Blazor appended child nodes directly to the <template> element instead of its associated content DocumentFragment. This behavior was not compliant with the HTML specification for HTMLTemplateElement, which requires all child content to be stored within template.content while the <template> element itself remains empty.

To address this, the rendering logic in LogicalElements has been updated to recognize HTMLTemplateElement instances and correctly insert rendered content into the element's content DocumentFragment. This ensures that the generated DOM structure aligns with native browser behavior and the HTML specification.

Before

image

After

image

Changes included

  • Updated appendDomNode in LogicalElements.ts to route DOM insertions through a container-resolution helper.
  • Added an internal getLogicalDomNodeContainer(parent) helper that resolves the correct DOM container for logical element operations:
    • Returns template.content for HTMLTemplateElement instances.
    • Returns the element itself for all other element types.
  • Added comprehensive test coverage for HTMLTemplateElement handling in LogicalElements.test.ts.

Fixes #50831

@Vinoth2562000 Vinoth2562000 requested a review from a team as a code owner July 8, 2026 07:36
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Jul 8, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Thanks for your PR, @Vinoth2562000. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Blazor messes up standard HTMLTemplateElement <template>

1 participant