Skip to content

Commit

Permalink
fix: render attributes during SSR regardless of case (#14492)
Browse files Browse the repository at this point in the history
fixes part of #14479
  • Loading branch information
Rich-Harris authored Dec 2, 2024
1 parent 83cec2f commit ef640c3
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/proud-crews-itch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: render attributes during SSR regardless of case
4 changes: 3 additions & 1 deletion packages/svelte/src/internal/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,13 @@ export function spread_attributes(attrs, classes, styles, flags = 0) {
if (name[0] === '$' && name[1] === '$') continue; // faster than name.startsWith('$$')
if (INVALID_ATTR_NAME_CHAR_REGEX.test(name)) continue;

var value = attrs[name];

if (lowercase) {
name = name.toLowerCase();
}

attr_str += attr(name, attrs[name], is_html && is_boolean_attribute(name));
attr_str += attr(name, value, is_html && is_boolean_attribute(name));
}

return attr_str;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { test } from '../../test';

export default test({
mode: ['hydrate'],

test({ assert, target, hydrate }) {
const svg = target.querySelector('svg');
const circle = target.querySelector('circle');

assert.equal(svg?.getAttribute('viewBox'), '0 0 1000 1000');
assert.equal(svg?.namespaceURI, 'http://www.w3.org/2000/svg');
assert.equal(circle?.namespaceURI, 'http://www.w3.org/2000/svg');

hydrate();

assert.equal(svg?.getAttribute('viewBox'), '0 0 1000 1000');
assert.equal(svg?.namespaceURI, 'http://www.w3.org/2000/svg');
assert.equal(circle?.namespaceURI, 'http://www.w3.org/2000/svg');
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<script>
let props = {
height: '100px',
width: '100px',
viewBox: '0 0 1000 1000'
};
</script>

<svelte:element this={'svg'} {...props}>
<circle cx="500" cy="500" r="500"></circle>
</svelte:element>

0 comments on commit ef640c3

Please sign in to comment.