Skip to content

Can't remove attribute from SVG element #43949

Closed
@SteveSandersonMS

Description

@SteveSandersonMS

This line of code:

if (element instanceof HTMLElement) {

... is wrong. It should work for SVGElement and HTMLElement, so at first glance at least, we should change it to if (element instanceof Element) {.

Repro

Click the rectangle:

<svg xmlns="http://www.w3.org/2000/svg" viewbox="0 0 100 100" width="100" height="100" @onclick="@(() => styleValue = null)">
    <rect x="0" y="0" width="100" height="100" style="@styleValue"></rect>
</svg>

@code {
    string? styleValue = "stroke: red";
}

The error is:

crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: Cannot remove attribute from non-element child
      Error: Cannot remove attribute from non-element child
          at se.applyEdits (https://localhost:7142/_framework/blazor.webassembly.js:1:21866)

Originally reported as #43858

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-blazorIncludes: Blazor, Razor Componentsgood first issueGood for newcomers.help wantedUp for grabs. We would accept a PR to help resolve this issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions