Skip to content

Commit 7dacf2c

Browse files
fix: use svg methods for updating svg attributes too (#11755)
Closes #11746 we were using the svg methods for every child of svg but not for svg itself
1 parent d15fd95 commit 7dacf2c

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

.changeset/green-snails-tickle.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"svelte": patch
3+
---
4+
5+
fix: use svg methods for updating svg attributes too

packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ function serialize_dynamic_element_attributes(attributes, context, element_id) {
472472
function serialize_element_attribute_update_assignment(element, node_id, attribute, context) {
473473
const state = context.state;
474474
const name = get_attribute_name(element, attribute, context);
475-
const is_svg = context.state.metadata.namespace === 'svg';
475+
const is_svg = context.state.metadata.namespace === 'svg' || element.name === 'svg';
476476
const is_mathml = context.state.metadata.namespace === 'mathml';
477477
let [contains_call_expression, value] = serialize_attribute_value(attribute.value, context);
478478

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { flushSync } from '../../../../src/index-client';
2+
import { test, ok } from '../../test';
3+
4+
export default test({
5+
mode: ['client'],
6+
test({ assert, target }) {
7+
const svg = target.querySelector('svg');
8+
const button = target.querySelector('button');
9+
ok(svg);
10+
ok(button);
11+
12+
assert.equal(svg.getAttribute('class'), '0');
13+
flushSync(() => {
14+
button.click();
15+
});
16+
assert.equal(svg.getAttribute('class'), '1');
17+
}
18+
});
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<script>
2+
let count = $state(0);
3+
</script>
4+
5+
<svg class={count}>
6+
</svg>
7+
8+
<button onclick={()=>count++}></button>

0 commit comments

Comments
 (0)