Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/useForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,10 @@ export class FormStore {
}
}

this.notifyWatch([namePath]);
// Avoid exponential loops when a large number of components are unloaded
Promise.resolve().then(() => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这样会破坏同步性,还是要想想其他方式

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果是担心修改暴露出去的registerField同步, 那给registerField增加第二个参数,registerField('a', { async: true }), 只修改内部Field组件调用,这样对外调用这个方法的时候就不会有影响了

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

还有个 bug,到时候一块看 ant-design/ant-design#54173

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

除了我说的这种对外暴露使用的情况外,我理解其它情况下用户也拿不到这个同步更新的值,因为这个时候还在react的commit阶段

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

看看这个 OK 不?

#757

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

看看这个 OK 不?

#757

OK的,这样更新时机更提前了

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

延后了

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

延后了

我是说对比promise.resolve的情况

this.notifyWatch([namePath]);
})
};
};

Expand Down
10 changes: 10 additions & 0 deletions tests/useWatch.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ describe('useWatch', () => {
expect(container.querySelector<HTMLDivElement>('.values')?.textContent).toEqual('bamboo');

rerender(<Demo visible={false} />);

await act(async () => {
await timeout();
});

expect(container.querySelector<HTMLDivElement>('.values')?.textContent).toEqual('');

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

rerender(<Demo visible={false} />);

await act(async () => {
await timeout();
});

expect(container.querySelector<HTMLDivElement>('.values')?.textContent).toEqual('');

rerender(<Demo visible />);
Expand Down