Closed panghaoyuan closed 2 years ago
[ ] I have searched the issues of this repository and believe that this is not a duplicate.
复现demo https://github.com/panghaoyuan/formily-bug-demo
git clone https://github.com/panghaoyuan/formily-bug-demo.git pnpm i pnpm dev
自定义组件可以触发阅读态
自定义组件无法触发阅读态
@formily/react@2.2.5
通过源码断点发现问题,但是无法解决问题,希望以下代码有参考价值 自定义组件中 useField() 为null
useField()
null
export function mapReadPretty(component, readPrettyProps) { return function (target) { return observer(function (props) { var field = useField(); // 自定义组件field为null if (!isVoidField(field) && (field === null || field === void 0 ? void 0 : field.pattern) === 'readPretty') { return React.createElement(component, __assign(__assign({}, readPrettyProps), props)); } return React.createElement(target, props); }, { forwardRef: true, }); }; }
https://github.com/alibaba/formily/blob/23b94cdb026f492d65bb5d8234e5d6e52dd22ae7/packages/react/src/shared/connect.ts#L47-L68
应该是打包问题,重复打包了,react context拿不到
@janryWang 我提供的issues里提供最小实现代码了,这个问题怎么解决,大佬能给个思路吗,或者帮我解决一下吗
@janryWang 找到问题了,,不是重复打包,是pnpm的包版本没对齐导致的问题,thank you.
[ ] I have searched the issues of this repository and believe that this is not a duplicate.
Reproduction link
复现demo https://github.com/panghaoyuan/formily-bug-demo
Steps to reproduce
What is expected?
自定义组件可以触发阅读态
What is actually happening?
自定义组件无法触发阅读态
Package
@formily/react@2.2.5
通过源码断点发现问题,但是无法解决问题,希望以下代码有参考价值 自定义组件中
useField()
为null
https://github.com/alibaba/formily/blob/23b94cdb026f492d65bb5d8234e5d6e52dd22ae7/packages/react/src/shared/connect.ts#L47-L68