Skip to content

Commit e9da67c

Browse files
zombieJclaude
andcommitted
fix: use macroTask before raf in delayFrame
The delayFrame function was using only raf, which could execute before useWatch's React render completes. useWatch updates are scheduled via macroTask (MessageChannel), and raf may run before or after macroTask depending on the environment. By adding macroTask before raf, we ensure the execution order is: 1. useWatch's macroTask executes → React setState 2. delayFrame's macroTask executes 3. raf executes → validation starts This guarantees useWatch has updated before rules validation runs. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent fc66fbb commit e9da67c

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/hooks/useNotifyWatch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { FormStore } from './useForm';
55
/**
66
* Call action with delay in macro task.
77
*/
8-
const macroTask = (fn: VoidFunction) => {
8+
export const macroTask = (fn: VoidFunction) => {
99
const channel = new MessageChannel();
1010
channel.port1.onmessage = fn;
1111
channel.port2.postMessage(null);

src/utils/delayUtil.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
import { macroTask } from '../hooks/useNotifyWatch';
12
import raf from '@rc-component/util/lib/raf';
23

34
export default async function delayFrame() {
45
return new Promise<void>(resolve => {
5-
raf(() => {
6-
resolve();
6+
macroTask(() => {
7+
raf(() => {
8+
resolve();
9+
});
710
});
811
});
912
}

0 commit comments

Comments
 (0)