Skip to content

Commit

Permalink
fix: use empty string value for boolean attributes on client side (fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pimlie committed Jun 7, 2019
1 parent a31877c commit eb4980c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/client/updaters/tag.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { booleanHtmlAttributes } from '../../shared/constants'
import { isUndefined } from '../../utils/is-type'
import { toArray, includes } from '../../utils/array'

Expand Down Expand Up @@ -51,7 +52,7 @@ export default function updateTag(appId, { attribute, tagIDKeyName } = {}, type,
const _attr = includes(dataAttributes, attr)
? `data-${attr}`
: attr
const value = isUndefined(tag[attr]) ? '' : tag[attr]
const value = isUndefined(tag[attr]) || booleanHtmlAttributes.includes(attr) ? '' : tag[attr]
newElement.setAttribute(_attr, value)
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/utils/meta-info-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ const metaInfoData = {
return () => {
if (side === 'client') {
for (const index in this.expect) {
this.expect[index] = this.expect[index].replace(/(async|defer)/g, '$1="true"')
this.expect[index] = this.expect[index].replace(/(async|defer)/g, '$1=""')
}
const tags = defaultTest()

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

0 comments on commit eb4980c

Please sign in to comment.