Skip to content

Commit 686aa0b

Browse files
authored
Merge pull request #3531 from sveltejs/gh-3522
only use setAttribute with SVG spread props
2 parents 41f5961 + 8519003 commit 686aa0b

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

src/compiler/compile/render_dom/wrappers/Element/index.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -610,12 +610,14 @@ export default class ElementWrapper extends Wrapper {
610610
}
611611
`);
612612

613+
const fn = this.node.namespace === namespaces.svg ? `set_svg_attributes` : `set_attributes`;
614+
613615
block.builders.hydrate.add_line(
614-
`@set_attributes(${this.var}, ${data});`
616+
`@${fn}(${this.var}, ${data});`
615617
);
616618

617619
block.builders.update.add_block(deindent`
618-
@set_attributes(${this.var}, @get_spread_update(${levels}, [
620+
@${fn}(${this.var}, @get_spread_update(${levels}, [
619621
${updates.join(',\n')}
620622
]));
621623
`);

src/runtime/internal/dom.ts

+6
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ export function set_attributes(node: Element & ElementCSSInlineStyle, attributes
101101
}
102102
}
103103

104+
export function set_svg_attributes(node: Element & ElementCSSInlineStyle, attributes: { [x: string]: string }) {
105+
for (const key in attributes) {
106+
attr(node, key, attributes[key]);
107+
}
108+
}
109+
104110
export function set_custom_element_data(node, prop, value) {
105111
if (prop in node) {
106112
node[prop] = value;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default {
2+
html: `
3+
<svg height="400" width="400">
4+
<rect x="50" y="50" width="100" height="75" fill="#ff0000"></rect>
5+
</svg>
6+
`
7+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<script>
2+
const style = { fill: '#ff0000', x: '50', y: '50', width: '100', height: '75'};
3+
</script>
4+
5+
<svg width="400" height="400">
6+
<rect {...style}/>
7+
</svg>

0 commit comments

Comments
 (0)