From 76557f431dfdb5b83a17009eac46d48cd2171e65 Mon Sep 17 00:00:00 2001 From: Rainke Date: Tue, 17 Oct 2023 21:41:42 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20hoc=20=E7=BB=84=E4=BB=B6=E7=BC=93?= =?UTF-8?q?=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/renderer-core/src/hoc/index.tsx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/renderer-core/src/hoc/index.tsx b/packages/renderer-core/src/hoc/index.tsx index 3715d776a..75795b7c4 100644 --- a/packages/renderer-core/src/hoc/index.tsx +++ b/packages/renderer-core/src/hoc/index.tsx @@ -62,6 +62,8 @@ function patchDidCatch(Comp: any, { baseRenderer }: Options) { } } +const cache = new Map(); + export function compWrapper(Comp: any, options: Options) { const { createElement, Component, forwardRef } = adapter.getRuntime(); if ( @@ -72,6 +74,11 @@ export function compWrapper(Comp: any, options: Options) { patchDidCatch(Comp, options); return Comp; } + + if (cache.has(options.schema.id)) { + return cache.get(options.schema.id); + } + class Wrapper extends Component { render() { return createElement(Comp, { ...this.props, ref: this.props.forwardRef }); @@ -82,10 +89,14 @@ export function compWrapper(Comp: any, options: Options) { patchDidCatch(Wrapper, options); patchDidMount(Wrapper, options); - return cloneEnumerableProperty( + const WrapperComponent = cloneEnumerableProperty( forwardRef((props: any, ref: any) => { return createElement(Wrapper, { ...props, forwardRef: ref }); }), Comp, ); + + cache.set(options.schema.id, WrapperComponent); + + return WrapperComponent; }