Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/compiler/compile/render_dom/wrappers/Element/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -610,12 +610,14 @@ export default class ElementWrapper extends Wrapper {
}
`);

const fn = this.node.namespace === namespaces.svg ? `set_svg_attributes` : `set_attributes`;

block.builders.hydrate.add_line(
`@set_attributes(${this.var}, ${data});`
`@${fn}(${this.var}, ${data});`
);

block.builders.update.add_block(deindent`
@set_attributes(${this.var}, @get_spread_update(${levels}, [
@${fn}(${this.var}, @get_spread_update(${levels}, [
${updates.join(',\n')}
]));
`);
Expand Down
6 changes: 6 additions & 0 deletions src/runtime/internal/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ export function set_attributes(node: Element & ElementCSSInlineStyle, attributes
}
}

export function set_svg_attributes(node: Element & ElementCSSInlineStyle, attributes: { [x: string]: string }) {
for (const key in attributes) {
attr(node, key, attributes[key]);
}
}

export function set_custom_element_data(node, prop, value) {
if (prop in node) {
node[prop] = value;
Expand Down
7 changes: 7 additions & 0 deletions test/runtime/samples/svg-spread/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default {
html: `
<svg height="400" width="400">
<rect x="50" y="50" width="100" height="75" fill="#ff0000"></rect>
</svg>
`
};
7 changes: 7 additions & 0 deletions test/runtime/samples/svg-spread/main.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script>
const style = { fill: '#ff0000', x: '50', y: '50', width: '100', height: '75'};
</script>

<svg width="400" height="400">
<rect {...style}/>
</svg>