diff --git a/src/useForm.ts b/src/useForm.ts index cb9c5f09..2578b87a 100644 --- a/src/useForm.ts +++ b/src/useForm.ts @@ -682,7 +682,10 @@ export class FormStore { } } - this.notifyWatch([namePath]); + // Avoid exponential loops when a large number of components are unloaded + Promise.resolve().then(() => { + this.notifyWatch([namePath]); + }) }; }; diff --git a/tests/useWatch.test.tsx b/tests/useWatch.test.tsx index 86be6cdb..fd5cd420 100644 --- a/tests/useWatch.test.tsx +++ b/tests/useWatch.test.tsx @@ -121,6 +121,11 @@ describe('useWatch', () => { expect(container.querySelector('.values')?.textContent).toEqual('bamboo'); rerender(); + + await act(async () => { + await timeout(); + }); + expect(container.querySelector('.values')?.textContent).toEqual(''); rerender(); @@ -158,6 +163,11 @@ describe('useWatch', () => { expect(container.querySelector('.values')?.textContent).toEqual('bamboo'); rerender(); + + await act(async () => { + await timeout(); + }); + expect(container.querySelector('.values')?.textContent).toEqual(''); rerender();