From df61d03dd74abc8c3557215bd895b29af3f4718f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B6=E6=9E=AB?= <7971419+crazyair@users.noreply.github.com> Date: Wed, 30 Oct 2024 19:08:58 +0800 Subject: [PATCH] fix: normalize as the same should not trigger onValuesChange (#731) --- src/Field.tsx | 14 +++++++------- tests/control.test.tsx | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/Field.tsx b/src/Field.tsx index 964fff125..335ac16b3 100644 --- a/src/Field.tsx +++ b/src/Field.tsx @@ -620,13 +620,13 @@ class Field extends React.Component implements F if (normalize) { newValue = normalize(newValue, value, getFieldsValue(true)); } - - dispatch({ - type: 'updateValue', - namePath, - value: newValue, - }); - + if (!isEqual(newValue, value)) { + dispatch({ + type: 'updateValue', + namePath, + value: newValue, + }); + } if (originTriggerFunc) { originTriggerFunc(...args); } diff --git a/tests/control.test.tsx b/tests/control.test.tsx index 88614292f..7aaec6d75 100644 --- a/tests/control.test.tsx +++ b/tests/control.test.tsx @@ -40,4 +40,18 @@ describe('Form.Control', () => { await changeValue(getInput(container), ['bamboo', '']); matchError(container, "'test' is required"); }); + + it('value no change', async () => { + const fn = jest.fn(); + const { container } = render( +
+ value?.replace(/\D/g, '') || undefined} /> + , + ); + + await changeValue(getInput(container), 'bamboo'); + expect(fn).toHaveBeenCalledTimes(0); + await changeValue(getInput(container), '1'); + expect(fn).toHaveBeenCalledTimes(1); + }); });