From 00b31b52440a00616b87cb19e9e05749a0fe5add Mon Sep 17 00:00:00 2001 From: zhoujunxiong Date: Tue, 17 Jun 2025 17:28:15 +0800 Subject: [PATCH 1/2] fix: Avoid exponential loops when a large number of components are unloaded --- src/useForm.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/useForm.ts b/src/useForm.ts index cb9c5f09..b1cf87d0 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 + setTimeout(() => { + this.notifyWatch([namePath]); + }) }; }; From ee1196c2e169bce98042b15b1ab6bb7eb9216e3e Mon Sep 17 00:00:00 2001 From: zhoujunxiong Date: Tue, 17 Jun 2025 18:28:09 +0800 Subject: [PATCH 2/2] fix: Optimize form notification and test stability --- src/useForm.ts | 2 +- tests/useWatch.test.tsx | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/useForm.ts b/src/useForm.ts index b1cf87d0..2578b87a 100644 --- a/src/useForm.ts +++ b/src/useForm.ts @@ -683,7 +683,7 @@ export class FormStore { } // Avoid exponential loops when a large number of components are unloaded - setTimeout(() => { + 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();