Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions packages/compiler-ssr/__tests__/ssrVShow.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ describe('ssr: v-show', () => {
const { ssrRenderAttrs: _ssrRenderAttrs } = require("vue/server-renderer")

return function ssrRender(_ctx, _push, _parent, _attrs) {
_push(\`<div\${_ssrRenderAttrs(_mergeProps({
_push(\`<div\${_ssrRenderAttrs(_mergeProps(_attrs, {
style: (_ctx.foo) ? null : { display: "none" }
}, _attrs))}></div>\`)
}))}></div>\`)
}"
`)
})
Expand Down Expand Up @@ -92,6 +92,24 @@ describe('ssr: v-show', () => {
`)
})

test('with style + display', () => {
expect(compileWithWrapper(`<div v-show="foo" style="display:flex" />`).code)
.toMatchInlineSnapshot(`
"const { ssrRenderStyle: _ssrRenderStyle, ssrRenderAttrs: _ssrRenderAttrs } = require("vue/server-renderer")

return function ssrRender(_ctx, _push, _parent, _attrs) {
_push(\`<div\${
_ssrRenderAttrs(_attrs)
}><div style="\${
_ssrRenderStyle([
{"display":"flex"},
(_ctx.foo) ? null : { display: "none" }
])
}"></div></div>\`)
}"
`)
})

test('with v-bind', () => {
expect(
compileWithWrapper(
Expand Down
11 changes: 11 additions & 0 deletions packages/compiler-ssr/src/transforms/ssrTransformElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,17 @@ export const ssrTransformElement: NodeTransform = (node, context) => {
const hasCustomDir = node.props.some(
p => p.type === NodeTypes.DIRECTIVE && !isBuiltInDirective(p.name),
)

// v-show has a higher priority in ssr
const vShowPropIndex = node.props.findIndex(
i => i.type === NodeTypes.DIRECTIVE && i.name === 'show',
)
if (vShowPropIndex !== -1) {
const vShowProp = node.props[vShowPropIndex]
node.props.splice(vShowPropIndex, 1)
node.props.push(vShowProp)
}

const needMergeProps = hasDynamicVBind || hasCustomDir
if (needMergeProps) {
const { props, directives } = buildProps(
Expand Down
Loading