feat(ssr): support custom directive getSSRProps in optimized compilation

close #5304
This commit is contained in:
Evan You
2022-02-04 08:58:28 +08:00
parent a51f935b72
commit 60cf175d88
14 changed files with 228 additions and 45 deletions

View File

@@ -10,8 +10,10 @@ import {
vShow,
vModelText,
vModelRadio,
vModelCheckbox
vModelCheckbox,
resolveDirective
} from 'vue'
import { ssrGetDirectiveProps, ssrRenderAttrs } from '../src'
describe('ssr: directives', () => {
describe('template v-show', () => {
@@ -374,7 +376,7 @@ describe('ssr: directives', () => {
})
})
test('custom directive w/ getSSRProps', async () => {
test('custom directive w/ getSSRProps (vdom)', async () => {
expect(
await renderToString(
createApp({
@@ -394,4 +396,35 @@ describe('ssr: directives', () => {
)
).toBe(`<div id="foo"></div>`)
})
test('custom directive w/ getSSRProps (optimized)', async () => {
expect(
await renderToString(
createApp({
data() {
return {
x: 'foo'
}
},
directives: {
xxx: {
getSSRProps({ value, arg, modifiers }) {
return { id: [value, arg, modifiers.ok].join('-') }
}
}
},
ssrRender(_ctx, _push, _parent, _attrs) {
const _directive_xxx = resolveDirective('xxx')!
_push(
`<div${ssrRenderAttrs(
ssrGetDirectiveProps(_ctx, _directive_xxx, _ctx.x, 'arg', {
ok: true
})
)}></div>`
)
}
})
)
).toBe(`<div id="foo-arg-true"></div>`)
})
})