[Bug Report] onFieldValueChange can trigger itself and Maximum call stack size exceeded
MeetzhDing opened this issue · 2 comments
MeetzhDing commented
- I have searched the issues of this repository and believe that this is not a duplicate.
Reproduction link
Steps to reproduce
复现地址
https://stackblitz.com/edit/formily-react-demo-hsycaf?file=package.json,src%2Fdemo%2FSchemaDemo.tsx
const form = createForm({
effects: () => {
onFieldValueChange('input', (field) => {
console.log(field.value)
// 这里修改这个值,会导致爆栈
field.setValue(field.value + '_');
});
},
});
effects 在设计上,是否应该像 xReactions 一样,在修改的时候不会导致其自身调用?
What is expected?
使用 onFieldHooks 注册的 reactions,不会调用自身
What is actually happening?
调用自身了,且最终导致栈溢出
Package
@formily/core@2.3.0
MeetzhDing commented
@janryWang @quirkyshop 这个现象是符合预期的吗?这个例子其实是简化后的,很多时候会出现调用到其他逻辑再调用回来产生的联动死循环
coolbob1998 commented
你这个写法有问题,死循环了。onFieldValueChange 就是通过监听当前字段值变化触发的。你在onFieldValueChange修改了当前字段值,肯定死循环了