[fix] ensure truthy non-boolean attributes are rendered correctly in SSR (#7066)

pull/7110/head
pngwn 3 years ago committed by GitHub
parent 966c03a317
commit 4240455e02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -2,6 +2,7 @@
## Unreleased ## Unreleased
* Fix non-boolean attribute rendering in SSR to render truthy values as-is ([#6121](https://github.com/sveltejs/svelte/issues/6121))
* Add `a11y-no-redundant-roles` warning ([#7067](https://github.com/sveltejs/svelte/pull/7067)) * Add `a11y-no-redundant-roles` warning ([#7067](https://github.com/sveltejs/svelte/pull/7067))
## 3.44.3 ## 3.44.3

@ -141,7 +141,7 @@ export function create_ssr_component(fn) {
export function add_attribute(name, value, boolean) { export function add_attribute(name, value, boolean) {
if (value == null || (boolean && !value)) return ''; if (value == null || (boolean && !value)) return '';
return ` ${name}${value === true ? '' : `=${typeof value === 'string' ? JSON.stringify(escape(value)) : `"${value}"`}`}`; return ` ${name}${value === true && boolean_attributes.has(name) ? '' : `=${typeof value === 'string' ? JSON.stringify(escape(value)) : `"${value}"`}`}`;
} }
export function add_classes(classes) { export function add_classes(classes) {

@ -1,7 +1,8 @@
export default { export default {
html: '<textarea readonly></textarea>', html: '<textarea readonly data-attr="true"></textarea>',
test({ assert, target }) { test({ assert, target }) {
const textarea = target.querySelector('textarea'); const textarea = target.querySelector('textarea');
assert.equal(textarea.dataset.attr, 'true');
assert.ok(textarea.readOnly); assert.ok(textarea.readOnly);
} }
}; };

@ -1 +1 @@
<textarea readonly="{true}"></textarea> <textarea readonly={true} data-attr={true} />

Loading…
Cancel
Save