From c5c31eccea901d1912d1d46da509782732940c96 Mon Sep 17 00:00:00 2001 From: shangqunfeng Date: Fri, 31 May 2024 16:01:00 +0800 Subject: [PATCH] fix(*): fix istext. --- .../lib/runtime/components/react/mpx-view.tsx | 7 ++++--- .../webpack-plugin/lib/runtime/components/react/utils.ts | 5 ----- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/packages/webpack-plugin/lib/runtime/components/react/mpx-view.tsx b/packages/webpack-plugin/lib/runtime/components/react/mpx-view.tsx index 9fcfca218b..8eb74f5bba 100644 --- a/packages/webpack-plugin/lib/runtime/components/react/mpx-view.tsx +++ b/packages/webpack-plugin/lib/runtime/components/react/mpx-view.tsx @@ -12,7 +12,7 @@ import useInnerProps from './getInnerListeners' // @ts-ignore import useNodesRef from '../../useNodesRef' // 引入辅助函数 -import { parseUrl, hasElementType, TEXT_STYLE_REGEX, PERCENT_REGX } from './utils' +import { parseUrl, TEXT_STYLE_REGEX, PERCENT_REGX } from './utils' type ElementNode = React.ReactNode @@ -237,8 +237,9 @@ function splitStyle(styles: ExtendedViewStyle) { }, {}) } -const isText = (children: ElementNode) => { - return hasElementType(children, 'mpx-text') || hasElementType(children, 'Text') +const isText = (ele: ElementNode) => { + const displayName = ele?.type?.displayName + return displayName === 'mpx-text' || displayName === 'Text' } function every(children: ElementNode, callback: (children: ElementNode) => boolean ) { diff --git a/packages/webpack-plugin/lib/runtime/components/react/utils.ts b/packages/webpack-plugin/lib/runtime/components/react/utils.ts index fc55134e53..df532841c4 100644 --- a/packages/webpack-plugin/lib/runtime/components/react/utils.ts +++ b/packages/webpack-plugin/lib/runtime/components/react/utils.ts @@ -72,11 +72,6 @@ export const parseUrl = (cssUrl: string = '') => { return match?.[1] } -export const hasElementType = (element: ReactNode, type: string) => { - if (!element) return false - return (element as any)?.type?.displayName === type -} - export const getRestProps = (transferProps: any = {}, originProps: any = {}, deletePropsKey: any = []) => { return { ...transferProps,