fix(compiler-ssr): fix component event handlers inheritance in ssr
fix #5664
This commit is contained in:
parent
4caa52120d
commit
f811dc2b60
@ -17,6 +17,20 @@ describe('ssr: components', () => {
|
|||||||
`)
|
`)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// event listeners should still be passed
|
||||||
|
test('event listeners', () => {
|
||||||
|
expect(compile(`<foo @click="bar" />`).code).toMatchInlineSnapshot(`
|
||||||
|
"const { resolveComponent: _resolveComponent, mergeProps: _mergeProps } = require(\\"vue\\")
|
||||||
|
const { ssrRenderComponent: _ssrRenderComponent } = require(\\"vue/server-renderer\\")
|
||||||
|
|
||||||
|
return function ssrRender(_ctx, _push, _parent, _attrs) {
|
||||||
|
const _component_foo = _resolveComponent(\\"foo\\")
|
||||||
|
|
||||||
|
_push(_ssrRenderComponent(_component_foo, _mergeProps({ onClick: _ctx.bar }, _attrs), null, _parent))
|
||||||
|
}"
|
||||||
|
`)
|
||||||
|
})
|
||||||
|
|
||||||
test('dynamic component', () => {
|
test('dynamic component', () => {
|
||||||
expect(compile(`<component is="foo" prop="b" />`).code)
|
expect(compile(`<component is="foo" prop="b" />`).code)
|
||||||
.toMatchInlineSnapshot(`
|
.toMatchInlineSnapshot(`
|
||||||
|
@ -10,7 +10,8 @@ import {
|
|||||||
trackSlotScopes,
|
trackSlotScopes,
|
||||||
noopDirectiveTransform,
|
noopDirectiveTransform,
|
||||||
transformBind,
|
transformBind,
|
||||||
transformStyle
|
transformStyle,
|
||||||
|
transformOn
|
||||||
} from '@vue/compiler-dom'
|
} from '@vue/compiler-dom'
|
||||||
import { ssrCodegenTransform } from './ssrCodegenTransform'
|
import { ssrCodegenTransform } from './ssrCodegenTransform'
|
||||||
import { ssrTransformElement } from './transforms/ssrTransformElement'
|
import { ssrTransformElement } from './transforms/ssrTransformElement'
|
||||||
@ -70,11 +71,12 @@ export function compile(
|
|||||||
directiveTransforms: {
|
directiveTransforms: {
|
||||||
// reusing core v-bind
|
// reusing core v-bind
|
||||||
bind: transformBind,
|
bind: transformBind,
|
||||||
|
on: transformOn,
|
||||||
// model and show has dedicated SSR handling
|
// model and show has dedicated SSR handling
|
||||||
model: ssrTransformModel,
|
model: ssrTransformModel,
|
||||||
show: ssrTransformShow,
|
show: ssrTransformShow,
|
||||||
// the following are ignored during SSR
|
// the following are ignored during SSR
|
||||||
on: noopDirectiveTransform,
|
// on: noopDirectiveTransform,
|
||||||
cloak: noopDirectiveTransform,
|
cloak: noopDirectiveTransform,
|
||||||
once: noopDirectiveTransform,
|
once: noopDirectiveTransform,
|
||||||
memo: noopDirectiveTransform,
|
memo: noopDirectiveTransform,
|
||||||
|
@ -194,7 +194,7 @@ export const ssrTransformElement: NodeTransform = (node, context) => {
|
|||||||
if (!needMergeProps) {
|
if (!needMergeProps) {
|
||||||
node.children = [createInterpolation(prop.exp, prop.loc)]
|
node.children = [createInterpolation(prop.exp, prop.loc)]
|
||||||
}
|
}
|
||||||
} else if (!needMergeProps) {
|
} else if (!needMergeProps && prop.name !== 'on') {
|
||||||
// Directive transforms.
|
// Directive transforms.
|
||||||
const directiveTransform = context.directiveTransforms[prop.name]
|
const directiveTransform = context.directiveTransforms[prop.name]
|
||||||
if (directiveTransform) {
|
if (directiveTransform) {
|
||||||
|
Loading…
Reference in New Issue
Block a user