Skip to content

Commit 3a1a23c

Browse files
author
lupengyu
committed
fix: add v-show style in ssr if style is binding to an array
web/server/directives/show just add style.display='none', no matter style is object or array; If style is an array, it will lost additional property while tranformed into object in shared/utils#toObject; fix vuejs#7813
1 parent 731b498 commit 3a1a23c

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/platforms/web/server/directives/show.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
export default function show (node: VNodeWithData, dir: VNodeDirective) {
44
if (!dir.value) {
55
const style: any = node.data.style || (node.data.style = {})
6-
style.display = 'none'
6+
if (Array.isArray(style)) {
7+
style.push({ display: 'none' })
8+
} else {
9+
style.display = 'none'
10+
}
711
}
812
}

test/ssr/ssr-string.spec.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,17 @@ describe('SSR: renderToString', () => {
267267
})
268268
})
269269

270+
it('v-show directive merge with style', done => {
271+
renderVmWithOptions({
272+
template: '<div :style="[{lineHeight: 1}]" v-show="false"><span>inner</span></div>'
273+
}, res => {
274+
expect(res).toContain(
275+
'<div data-server-rendered="true" style="line-height:1;display:none;"><span>inner</span></div>'
276+
)
277+
done()
278+
})
279+
})
280+
270281
it('v-show directive not passed to child', done => {
271282
renderVmWithOptions({
272283
template: '<foo v-show="false"></foo>',

0 commit comments

Comments
 (0)