Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug Report] onFieldValueChange can trigger itself and Maximum call stack size exceeded #4040

Closed
1 task
MeetzhDing opened this issue Dec 4, 2023 · 2 comments

Comments

@MeetzhDing
Copy link
Contributor

  • I have searched the issues of this repository and believe that this is not a duplicate.

Reproduction link

Edit

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/[email protected]


@MeetzhDing
Copy link
Contributor Author

@janryWang @quirkyshop 这个现象是符合预期的吗?这个例子其实是简化后的,很多时候会出现调用到其他逻辑再调用回来产生的联动死循环

@coolbob1998
Copy link
Contributor

你这个写法有问题,死循环了。onFieldValueChange 就是通过监听当前字段值变化触发的。你在onFieldValueChange修改了当前字段值,肯定死循环了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants