Repository navigation
fix(html): set attribute for expressions on nested svg elements - #316
Merged
smalluban merged 1 commit intoSep 25, 2026
Merged
Conversation
Since 8.2.20 the property resolver only skips the `<svg>` root element. An
expression like `<rect x="${x}">` inside an `html` template therefore
assigns the read-only `x` property (`SVGAnimatedLength`) and throws a
TypeError.
Check for `SVGElement` again, as up to 8.2.19 and as the mixed-value path
in core.js still does, so expressions on elements in the SVG namespace set
attributes, like in `svg` templates.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #315.
Since 8.2.20, an expression in an attribute of a nested SVG element in an
htmltemplate (e.g.<rect x="${x}">) throws aTypeErrorwhen the element has a read-only property of that name (x,width,points,transform,hrefon<use>,viewBoxon<symbol>, …). Reproduction and version table in #315.resolveProperty()only skips the<svg>root (src/template/resolvers/property.js:35,isProp = target.tagName !== "svg";). For<rect>,"x" in targetis true (getter-onlySVGAnimatedLength), so the assignment inproperty.js:48throws in module code. TheSVGElementcheck was introduced in 6000823 ("svg element expressions always set attribute value") and kept until 8.2.19; bdd8716 (#253) replaced it with the tag-name check while adding the camel-case fallback. The mixed-value path still checks forSVGElement(src/template/core.js:433-435), and the "svg element" tests only cover the<svg>root.The docs suggest the
svgfunction for the internal structure of<svg>(docs/component-model/templates.md:47). Buthtmlalready parses nested SVG elements into the SVG namespace, static attributes and mixed values work, and single expressions worked up to 8.2.19, so the TypeError looks unintended.This change restores the
SVGElementcheck. Elements in the SVG namespace get attributes, as insvgtemplates and with mixed values. HTML and custom elements, also inside<foreignObject>, keep the property lookup and the camel-case fallback from bdd8716.Side effect: a writable property without an attribute on an SVG child in an
htmltemplate, such astextContent="${text}"on<text>, is set as an attribute again, as in 8.2.19 and insvgtemplates. Since 8.2.20 it has been set as a property. Properties that reflect an attribute, such astabIndex, give the same result either way.Regression test in
test/spec/html.js("svg element"):<rect x width>and<polyline points>inside<svg>in anhtmltemplate. It fails without the fix (Chrome Headless:Cannot set property x of #<SVGRectElement> which has only a getter, WebKit:Attempted to assign to readonly property.) and passes with it. Full suite in Chrome Headless and WebKit: 609 of 609 with the fix, 608 of 609 without it (mainalone in Chrome Headless: 608 of 608). Firefox was not run locally. Lint is clean, and prettier is clean for the changed files.