File tree Expand file tree Collapse file tree 2 files changed +62
-5
lines changed
packages/unhead/src/plugins Expand file tree Collapse file tree 2 files changed +62
-5
lines changed Original file line number Diff line number Diff line change @@ -36,12 +36,16 @@ export default defineHeadPlugin({
3636 const oldProps = dupedTag . props
3737 // apply oldProps to current props
3838 ; [ 'class' , 'style' ] . forEach ( ( key ) => {
39- if ( tag . props [ key ] && oldProps [ key ] ) {
40- // ensure style merge doesn't result in invalid css
41- if ( key === 'style' && ! oldProps [ key ] . endsWith ( ';' ) )
42- oldProps [ key ] += ';'
39+ if ( oldProps [ key ] ) {
40+ if ( tag . props [ key ] ) {
41+ // ensure style merge doesn't result in invalid css
42+ if ( key === 'style' && ! oldProps [ key ] . endsWith ( ';' ) )
43+ oldProps [ key ] += ';'
4344
44- tag . props [ key ] = `${ oldProps [ key ] } ${ tag . props [ key ] } `
45+ tag . props [ key ] = `${ oldProps [ key ] } ${ tag . props [ key ] } `
46+ } else {
47+ tag . props [ key ] = oldProps [ key ]
48+ }
4549 }
4650 } )
4751 deduping [ dedupeKey ] . props = {
Original file line number Diff line number Diff line change @@ -109,4 +109,57 @@ describe('resolveTags', () => {
109109 ]
110110 ` )
111111 } )
112+ it ( 'resolve multiple conditional classes entries' , async ( ) => {
113+ const head = createHead ( )
114+ setHeadInjectionHandler ( ( ) => head )
115+
116+ useHead ( {
117+ htmlAttrs : {
118+ class : {
119+ someTrue : true ,
120+ } ,
121+ } ,
122+ } )
123+
124+ useHead ( {
125+ htmlAttrs : {
126+ class : [ 'someArrayClass' ] ,
127+ } ,
128+ } )
129+
130+ useHead ( {
131+ htmlAttrs : {
132+ class : {
133+ someFalsy : false ,
134+ } ,
135+ } ,
136+ } )
137+
138+ useHead ( {
139+ htmlAttrs : {
140+ class : [ ] ,
141+ } ,
142+ } )
143+
144+ useHead ( {
145+ htmlAttrs : {
146+ class : '' ,
147+ } ,
148+ } )
149+
150+ const tags = await head . resolveTags ( )
151+ expect ( tags ) . toMatchInlineSnapshot ( `
152+ [
153+ {
154+ "_d": "htmlAttrs",
155+ "_e": 0,
156+ "_p": 0,
157+ "props": {
158+ "class": "someTrue someArrayClass",
159+ },
160+ "tag": "htmlAttrs",
161+ },
162+ ]
163+ ` )
164+ } )
112165} )
You can’t perform that action at this time.
0 commit comments