diff --git a/CHANGELOG.md b/CHANGELOG.md index 4081405811..dbf2c6fac2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## 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)) ## 3.44.3 diff --git a/src/runtime/internal/ssr.ts b/src/runtime/internal/ssr.ts index fd72aa1548..4d91857ad4 100644 --- a/src/runtime/internal/ssr.ts +++ b/src/runtime/internal/ssr.ts @@ -141,7 +141,7 @@ export function create_ssr_component(fn) { export function add_attribute(name, value, boolean) { 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) { diff --git a/test/runtime/samples/attribute-boolean-true/_config.js b/test/runtime/samples/attribute-boolean-true/_config.js index 79c8ea1ad6..89b2fc7c21 100644 --- a/test/runtime/samples/attribute-boolean-true/_config.js +++ b/test/runtime/samples/attribute-boolean-true/_config.js @@ -1,7 +1,8 @@ export default { - html: '', + html: '', test({ assert, target }) { const textarea = target.querySelector('textarea'); + assert.equal(textarea.dataset.attr, 'true'); assert.ok(textarea.readOnly); } }; diff --git a/test/runtime/samples/attribute-boolean-true/main.svelte b/test/runtime/samples/attribute-boolean-true/main.svelte index 04d5cab8f9..6474644749 100644 --- a/test/runtime/samples/attribute-boolean-true/main.svelte +++ b/test/runtime/samples/attribute-boolean-true/main.svelte @@ -1 +1 @@ - \ No newline at end of file +