Match-id-911ddde5daae9334dfb713f8153ba2885a919dff

This commit is contained in:
* 2023-03-20 09:57:25 +08:00
commit b0023eba05
2 changed files with 23 additions and 6 deletions

View File

@ -13,12 +13,20 @@
* See the Mulan PSL v2 for more details.
*/
import { TYPE_FORWARD_REF } from '../../external/JSXElementType';
import {TYPE_FORWARD_REF, TYPE_MEMO} from '../../external/JSXElementType';
export function forwardRef(render: Function) {
return {
vtype: TYPE_FORWARD_REF,
$$typeof: TYPE_FORWARD_REF, // 规避三方件hoist-non-react-statics中通过$$typeof获取类型但获取不到导致的错误
const forwardRefJSXElement = {
$$typeof: TYPE_FORWARD_REF, // 规避三方件hoist-non-react-statics中通过$$typeof获取类型但获取不到导致render被覆盖
render,
};
// 控制vtype不能修改规避三方件hoist-non-react-statics修改vtype导致问题
Object.defineProperty(forwardRefJSXElement, 'vtype', {
configurable: false,
writable: false,
value: TYPE_FORWARD_REF,
});
return forwardRefJSXElement;
}

View File

@ -16,9 +16,18 @@
import { TYPE_MEMO } from '../../external/JSXElementType';
export function memo<Props>(type, compare?: (oldProps: Props, newProps: Props) => boolean) {
return {
vtype: TYPE_MEMO,
const memoJSXElement = {
$$typeof: TYPE_MEMO, // 规避三方件hoist-non-react-statics中通过$$typeof获取类型但获取不到导致type被覆盖
type: type,
compare: compare === undefined ? null : compare,
};
// 控制vtype不能修改规避三方件hoist-non-react-statics修改vtype导致问题
Object.defineProperty(memoJSXElement, 'vtype', {
configurable: false,
writable: false,
value: TYPE_MEMO,
});
return memoJSXElement;
}