From ff859d3343d6b25c739d98aebc8d303cb9e2fb94 Mon Sep 17 00:00:00 2001 From: crazyair <645381995@qq.com> Date: Wed, 30 Oct 2024 18:16:11 +0800 Subject: [PATCH] fix: change --- 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); + }); });