diff --git a/src/Field.tsx b/src/Field.tsx index 1b9d1cba..964fff12 100644 --- a/src/Field.tsx +++ b/src/Field.tsx @@ -297,7 +297,10 @@ class Field extends React.Component implements F * - Reset A, need clean B, C */ case 'remove': { - if (shouldUpdate) { + if ( + shouldUpdate && + requireUpdate(shouldUpdate, prevStore, store, prevValue, curValue, info) + ) { this.reRender(); return; } diff --git a/tests/dependencies.test.tsx b/tests/dependencies.test.tsx index 82d986a3..a06facd3 100644 --- a/tests/dependencies.test.tsx +++ b/tests/dependencies.test.tsx @@ -226,4 +226,43 @@ describe('Form.Dependencies', () => { // sync end expect(spy).toHaveBeenCalledTimes(3); }); + + it('shouldUpdate false should not update', () => { + let counter = 0; + const formRef = React.createRef(); + + const { container } = render( +
+ + + + + prev.little !== next.little}> + {(_, __, form) => { + // Fill to hide + if (!form.getFieldValue('little')) { + return ; + } + + return null; + }} + + + false}> + {() => { + console.log('render!'); + counter += 1; + return null; + }} + +
, + ); + expect(counter).toEqual(1); + expect(container.querySelectorAll('input')).toHaveLength(2); + + // hide should not re-render + fireEvent.change(getInput(container, 0), { target: { value: '1' } }); + expect(container.querySelectorAll('input')).toHaveLength(1); + expect(counter).toEqual(1); + }); });