Skip to content

fix: render attributes during SSR regardless of case #14492

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

Merged
merged 1 commit into from
Dec 2, 2024
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
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>