Skip to content

Commit ee1196c

Browse files
author
zhoujunxiong
committed
fix: Optimize form notification and test stability
1 parent 00b31b5 commit ee1196c

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/useForm.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ export class FormStore {
683683
}
684684

685685
// Avoid exponential loops when a large number of components are unloaded
686-
setTimeout(() => {
686+
Promise.resolve().then(() => {
687687
this.notifyWatch([namePath]);
688688
})
689689
};

tests/useWatch.test.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ describe('useWatch', () => {
121121
expect(container.querySelector<HTMLDivElement>('.values')?.textContent).toEqual('bamboo');
122122

123123
rerender(<Demo visible={false} />);
124+
125+
await act(async () => {
126+
await timeout();
127+
});
128+
124129
expect(container.querySelector<HTMLDivElement>('.values')?.textContent).toEqual('');
125130

126131
rerender(<Demo visible />);
@@ -158,6 +163,11 @@ describe('useWatch', () => {
158163
expect(container.querySelector<HTMLDivElement>('.values')?.textContent).toEqual('bamboo');
159164

160165
rerender(<Demo visible={false} />);
166+
167+
await act(async () => {
168+
await timeout();
169+
});
170+
161171
expect(container.querySelector<HTMLDivElement>('.values')?.textContent).toEqual('');
162172

163173
rerender(<Demo visible />);

0 commit comments

Comments
 (0)