fix(runtime-dom): consistently remove boolean attributes for falsy values (#4348)
This commit is contained in:
@@ -50,9 +50,11 @@ describe('ssr: renderAttrs', () => {
|
||||
expect(
|
||||
ssrRenderAttrs({
|
||||
checked: true,
|
||||
multiple: false
|
||||
multiple: false,
|
||||
readonly: 0,
|
||||
disabled: ''
|
||||
})
|
||||
).toBe(` checked`) // boolean attr w/ false should be ignored
|
||||
).toBe(` checked disabled`) // boolean attr w/ false should be ignored
|
||||
})
|
||||
|
||||
test('ignore falsy values', () => {
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
isOn,
|
||||
isSSRSafeAttrName,
|
||||
isBooleanAttr,
|
||||
includeBooleanAttr,
|
||||
makeMap
|
||||
} from '@vue/shared'
|
||||
|
||||
@@ -52,7 +53,7 @@ export function ssrRenderDynamicAttr(
|
||||
? key // preserve raw name on custom elements
|
||||
: propsToAttrMap[key] || key.toLowerCase()
|
||||
if (isBooleanAttr(attrKey)) {
|
||||
return value === false ? `` : ` ${attrKey}`
|
||||
return includeBooleanAttr(value) ? ` ${attrKey}` : ``
|
||||
} else if (isSSRSafeAttrName(attrKey)) {
|
||||
return value === '' ? ` ${attrKey}` : ` ${attrKey}="${escapeHtml(value)}"`
|
||||
} else {
|
||||
|
||||
@@ -27,6 +27,7 @@ export {
|
||||
export { ssrInterpolate } from './helpers/ssrInterpolate'
|
||||
export { ssrRenderList } from './helpers/ssrRenderList'
|
||||
export { ssrRenderSuspense } from './helpers/ssrRenderSuspense'
|
||||
export { includeBooleanAttr as ssrIncludeBooleanAttr } from '@vue/shared'
|
||||
|
||||
// v-model helpers
|
||||
export {
|
||||
|
||||
Reference in New Issue
Block a user