Skip to content

Commit aabcf72

Browse files
zombieJclaude
andcommitted
feat: await next frame before validation to support useWatch in rules
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 026e609 commit aabcf72

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/Field.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import toChildrenArray from '@rc-component/util/lib/Children/toArray';
22
import isEqual from '@rc-component/util/lib/isEqual';
33
import warning from '@rc-component/util/lib/warning';
44
import * as React from 'react';
5+
import raf from '@rc-component/util/lib/raf';
56
import FieldContext, { HOOK_MARK } from './FieldContext';
67
import type {
78
EventArgs,
@@ -99,8 +100,10 @@ export interface InternalFieldProps<Values = any> {
99100
fieldContext?: InternalFormInstance;
100101
}
101102

102-
export interface FieldProps<Values = any>
103-
extends Omit<InternalFieldProps<Values>, 'name' | 'fieldContext'> {
103+
export interface FieldProps<Values = any> extends Omit<
104+
InternalFieldProps<Values>,
105+
'name' | 'fieldContext'
106+
> {
104107
name?: NamePath<Values>;
105108
}
106109

@@ -399,6 +402,10 @@ class Field extends React.Component<InternalFieldProps, FieldState> implements F
399402

400403
const { validateFirst = false, messageVariables, validateDebounce } = this.props;
401404

405+
// Should wait for the frame render,
406+
// since developer may `useWatch` value in the rules.
407+
await new Promise<void>(resolve => raf(() => resolve()));
408+
402409
// Start validate
403410
let filteredRules = this.getRules();
404411
if (triggerName) {

0 commit comments

Comments
 (0)