Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] skip custom element check if <svelte:element> uses under svg #7869

Merged
merged 2 commits into from
Sep 15, 2022
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
14 changes: 8 additions & 6 deletions src/compiler/compile/render_dom/wrappers/Element/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -806,12 +806,14 @@ export default class ElementWrapper extends Wrapper {
if (this.node.is_dynamic_element) {
// call attribute bindings for custom element if tag is custom element
const tag = this.node.tag_expr.manipulate(block);
const attr_update = b`
if (/-/.test(${tag})) {
@set_custom_element_data_map(${this.var}, ${data});
} else {
${fn}(${this.var}, ${data});
}`;
const attr_update = this.node.namespace === namespaces.svg
? b`${fn}(${this.var}, ${data});`
: b`
if (/-/.test(${tag})) {
@set_custom_element_data_map(${this.var}, ${data});
} else {
${fn}(${this.var}, ${data});
}`;
block.chunks.hydrate.push(attr_update);
block.chunks.update.push(b`
${data} = @get_spread_update(${levels}, [${updates}]);
Expand Down
8 changes: 5 additions & 3 deletions test/js/samples/svelte-element-svg/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ function create_dynamic_element(ctx) {
append(svelte_element1, svelte_element0);
},
p(ctx, dirty) {
set_svg_attributes(svelte_element0, svelte_element0_data = get_spread_update(svelte_element0_levels, [{ xmlns: "http://www.w3.org/2000/svg" }]));
set_svg_attributes(svelte_element1, svelte_element1_data = get_spread_update(svelte_element1_levels, [{ xmlns: "http://www.w3.org/2000/svg" }]));
svelte_element0_data = get_spread_update(svelte_element0_levels, [{ xmlns: "http://www.w3.org/2000/svg" }]);
set_svg_attributes(svelte_element0, svelte_element0_data);
svelte_element1_data = get_spread_update(svelte_element1_levels, [{ xmlns: "http://www.w3.org/2000/svg" }]);
set_svg_attributes(svelte_element1, svelte_element1_data);
},
d(detaching) {
if (detaching) detach(svelte_element1);
Expand Down Expand Up @@ -108,4 +110,4 @@ class Component extends SvelteComponent {
}
}

export default Component;
export default Component;
10 changes: 10 additions & 0 deletions test/runtime/samples/dynamic-element-svg/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default {
html: '<svg xmlns="http://www.w3.org/2000/svg"><path xmlns="http://www.w3.org/2000/svg"></path></svg>',

test({ assert, target }) {
const svg = target.querySelector('svg');
const rect = target.querySelector('path');
assert.equal(svg.namespaceURI, 'http://www.w3.org/2000/svg');
assert.equal(rect.namespaceURI, 'http://www.w3.org/2000/svg');
}
};
3 changes: 3 additions & 0 deletions test/runtime/samples/dynamic-element-svg/main.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<svelte:element this="svg" xmlns="http://www.w3.org/2000/svg">
<svelte:element this="path" xmlns="http://www.w3.org/2000/svg"></svelte:element>
</svelte:element>