Skip to content

Commit 66e4fb4

Browse files
committed
fix: also render boolean attributes correctly for tags
1 parent deea5cf commit 66e4fb4

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

src/server/generators/tag.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { tagsWithoutEndTag, tagsWithInnerContent, tagAttributeAsInnerContent } from '../../shared/constants'
1+
import { booleanHtmlAttributes, tagsWithoutEndTag, tagsWithInnerContent, tagAttributeAsInnerContent } from '../../shared/constants'
22
import { isUndefined } from '../../shared/typeof'
33

44
/**
@@ -36,7 +36,7 @@ export default function tagGenerator({ attribute, tagIDKeyName } = {}, type, tag
3636
prefix = 'data-'
3737
}
3838

39-
return isUndefined(tag[attr])
39+
return isUndefined(tag[attr]) || booleanHtmlAttributes.includes(attr)
4040
? `${attrsStr} ${prefix}${attr}`
4141
: `${attrsStr} ${prefix}${attr}="${tag[attr]}"`
4242
}, '')

test/utils/meta-info-data.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,15 @@ const metaInfoData = {
117117
{ src: 'src', async: true, defer: true, body: true }
118118
],
119119
expect: [
120-
'<script data-vue-meta="true" src="src" async="true" defer="true" data-vmid="content"></script>',
121-
'<script data-vue-meta="true" src="src" async="true" defer="true" data-body="true"></script>'
120+
'<script data-vue-meta="true" src="src" async defer data-vmid="content"></script>',
121+
'<script data-vue-meta="true" src="src" async defer data-body="true"></script>'
122122
],
123123
test(side, defaultTest) {
124124
return () => {
125125
if (side === 'client') {
126+
for (const index in this.expect) {
127+
this.expect[index] = this.expect[index].replace(/(async|defer)/g, '$1="true"')
128+
}
126129
const tags = defaultTest()
127130

128131
expect(tags.addedTags.script[0].parentNode.tagName).toBe('HEAD')
@@ -139,15 +142,10 @@ const metaInfoData = {
139142
}
140143
}
141144
},
145+
// this test only runs for client so we can directly expect wrong boolean attributes
142146
change: {
143147
data: [{ src: 'src', async: true, defer: true, [defaultOptions.tagIDKeyName]: 'content2' }],
144-
expect: ['<script data-vue-meta="true" src="src" async="true" defer data-vmid="content2"></script>'],
145-
test(side, defaultTest) {
146-
if (side === 'client') {
147-
// jsdom doesnt generate valid boolean attributes
148-
this.expect[0] = this.expect[0].replace('defer', 'defer="true"')
149-
}
150-
}
148+
expect: ['<script data-vue-meta="true" src="src" async="true" defer="true" data-vmid="content2"></script>']
151149
},
152150
remove: {
153151
data: [],

0 commit comments

Comments
 (0)