Skip to content

feat: add <svelte:html> element #14397

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

Draft
wants to merge 22 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
better server attribute stringification
  • Loading branch information
dummdidumm committed Dec 18, 2024
commit eb7a516770250490162b2fdf3e53a8751d23445c
5 changes: 2 additions & 3 deletions packages/svelte/src/internal/server/blocks/svelte-html.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/** @import { Payload } from '#server' */

import { escape_html } from '../../../escaping.js';
import { svelte_html_duplicate_attribute } from '../../shared/warnings.js';

/**
Expand All @@ -14,12 +13,12 @@ export function svelte_html(payload, attributes) {
if (payload.htmlAttributes.has(name)) {
if (name === 'class') {
// Don't bother deduplicating class names, the browser handles it just fine
value = `${payload.htmlAttributes.get(name)} ${value}`;
value = `${payload.htmlAttributes.get(name)} ${value}`.trim();
} else {
svelte_html_duplicate_attribute(name);
}
}

payload.htmlAttributes.set(name, escape_html(value, true));
payload.htmlAttributes.set(name, value);
}
}
5 changes: 3 additions & 2 deletions packages/svelte/src/internal/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,9 @@ export function render(component, options = {}) {
html: payload.out,
body: payload.out,
htmlAttributes: [...payload.htmlAttributes]
.map(([name, value]) => `${name}="${value}"`)
.join(' ')
.map(([name, value]) => attr(name, value, is_boolean_attribute(name)))
.join('')
.trim()
};
}

Expand Down
Loading