Skip to content

Commit eb4980c

Browse files
committed
fix: use empty string value for boolean attributes on client side (fixes #381)
1 parent a31877c commit eb4980c

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/client/updaters/tag.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { booleanHtmlAttributes } from '../../shared/constants'
12
import { isUndefined } from '../../utils/is-type'
23
import { toArray, includes } from '../../utils/array'
34

@@ -51,7 +52,7 @@ export default function updateTag(appId, { attribute, tagIDKeyName } = {}, type,
5152
const _attr = includes(dataAttributes, attr)
5253
? `data-${attr}`
5354
: attr
54-
const value = isUndefined(tag[attr]) ? '' : tag[attr]
55+
const value = isUndefined(tag[attr]) || booleanHtmlAttributes.includes(attr) ? '' : tag[attr]
5556
newElement.setAttribute(_attr, value)
5657
}
5758
}

test/utils/meta-info-data.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ const metaInfoData = {
124124
return () => {
125125
if (side === 'client') {
126126
for (const index in this.expect) {
127-
this.expect[index] = this.expect[index].replace(/(async|defer)/g, '$1="true"')
127+
this.expect[index] = this.expect[index].replace(/(async|defer)/g, '$1=""')
128128
}
129129
const tags = defaultTest()
130130

@@ -145,7 +145,7 @@ const metaInfoData = {
145145
// this test only runs for client so we can directly expect wrong boolean attributes
146146
change: {
147147
data: [{ src: 'src', async: true, defer: true, [defaultOptions.tagIDKeyName]: 'content2' }],
148-
expect: ['<script data-vue-meta="test" src="src" async="true" defer="true" data-vmid="content2"></script>']
148+
expect: ['<script data-vue-meta="test" src="src" async="" defer="" data-vmid="content2"></script>']
149149
},
150150
remove: {
151151
data: [],

0 commit comments

Comments
 (0)