From a4a78e130b40f32c5472d9d3e7c89e4642842a11 Mon Sep 17 00:00:00 2001 From: MisicDemone <424532913@qq.com> Date: Mon, 25 Apr 2022 14:50:49 +0800 Subject: [PATCH 1/2] fix(vue): fix render loop cause by functional component in mapProps --- packages/vue/src/shared/connect.ts | 55 +++++++++--------------------- 1 file changed, 17 insertions(+), 38 deletions(-) diff --git a/packages/vue/src/shared/connect.ts b/packages/vue/src/shared/connect.ts index 2d7e37c188b..b5c679787cd 100644 --- a/packages/vue/src/shared/connect.ts +++ b/packages/vue/src/shared/connect.ts @@ -36,48 +36,27 @@ export function mapProps( }, input) return (target: T) => { - /* istanbul ignore else */ - if (isVue2) { - return defineComponent>({ - functional: true, + return observer( + defineComponent({ name: target.name ? `Connected${target.name}` : `ConnectedComponent`, - render(createElement, context) { + setup(props, { attrs, slots, listeners }) { const fieldRef = useField() - const { data } = context - const attrs = fieldRef.value - ? transform( - { ...data.attrs, ...data.props } as VueComponentProps, - fieldRef.value - ) - : { ...data.attrs, ...data.props } - return createElement(target, { ...data, attrs }, context.children) + return () => { + const newAttrs = fieldRef.value + ? transform({ ...attrs } as VueComponentProps, fieldRef.value) + : { ...attrs } + return h( + target, + { + attrs: newAttrs, + on: listeners, + }, + slots + ) + } }, }) - } else { - return observer( - defineComponent({ - name: target.name ? `Connected${target.name}` : `ConnectedComponent`, - setup(props, { attrs, slots }) { - const fieldRef = useField() - return () => { - const newAttrs = fieldRef.value - ? transform( - { ...attrs } as VueComponentProps, - fieldRef.value - ) - : { ...attrs } - return h( - target, - { - attrs: newAttrs, - }, - slots - ) - } - }, - }) - ) - } + ) } } From 518c4e5a15fdb3c21aeef2d04ad0dd9ef3702496 Mon Sep 17 00:00:00 2001 From: MisicDemone <424532913@qq.com> Date: Mon, 25 Apr 2022 15:04:11 +0800 Subject: [PATCH 2/2] fix(vue): fix type error --- packages/vue/src/shared/connect.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vue/src/shared/connect.ts b/packages/vue/src/shared/connect.ts index b5c679787cd..6eb98c1b280 100644 --- a/packages/vue/src/shared/connect.ts +++ b/packages/vue/src/shared/connect.ts @@ -39,7 +39,7 @@ export function mapProps( return observer( defineComponent({ name: target.name ? `Connected${target.name}` : `ConnectedComponent`, - setup(props, { attrs, slots, listeners }) { + setup(props, { attrs, slots, listeners }: any) { const fieldRef = useField() return () => { const newAttrs = fieldRef.value