fix: keep boolean attributes with an empty string value when rendering attribute objects on the server (#18721)

`<input disabled="" {...props}>` and any other boolean attribute written as `""` now renders on the server the way it does on the client and in plain markup.
pull/18722/head
Nic Polumeyv 1 month ago committed by GitHub
parent 2e8b57bc58
commit 7c6f36aa92
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: keep boolean attributes with an empty string value when rendering attribute objects on the server

@ -27,7 +27,8 @@ export function attr(name, value, is_boolean = false) {
if (name === 'hidden' && value !== 'until-found') {
is_boolean = true;
}
if (value == null || (!value && is_boolean)) return '';
// `''` is a present boolean attribute, as it is in markup and on the client
if (value == null || (is_boolean && !value && value !== '')) return '';
const normalized =
(has_own_property.call(replacements, name) && replacements[name].get(value)) || value;
const assignment = is_boolean ? `=""` : `="${escape_html(normalized, true)}"`;

@ -0,0 +1,6 @@
<input disabled="">
<input hidden="">
<input>
<select multiple="">
<option selected="" value="a">A</option>
</select>

@ -0,0 +1,10 @@
<script>
const props = {};
</script>
<input disabled="" {...props} />
<input hidden="" {...props} />
<input disabled={false} {...props} />
<select multiple="" value="a">
<option value="a">A</option>
</select>
Loading…
Cancel
Save