From 4240455e02f38a22f82a4b6e117b59af1b181e0c Mon Sep 17 00:00:00 2001 From: pngwn Date: Thu, 6 Jan 2022 15:14:09 +0000 Subject: [PATCH] [fix] ensure truthy non-boolean attributes are rendered correctly in SSR (#7066) --- CHANGELOG.md | 1 + src/runtime/internal/ssr.ts | 2 +- test/runtime/samples/attribute-boolean-true/_config.js | 3 ++- test/runtime/samples/attribute-boolean-true/main.svelte | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) 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 +