Skip to content

chore: add delayFrame option to validateFields#777

Merged
zombieJ merged 3 commits intomasterfrom
feature/delayFrame-option
Mar 4, 2026
Merged

chore: add delayFrame option to validateFields#777
zombieJ merged 3 commits intomasterfrom
feature/delayFrame-option

Conversation

@zombieJ
Copy link
Member

@zombieJ zombieJ commented Mar 4, 2026

  • Add delayFrame option to InternalValidateOptions interface
  • Conditionally call delayFrame when delayFrame option is true in Field.validateRules
  • Use delayFrame: true in triggerDependenciesUpdate to avoid useWatch rule timing issues
  • Adjust test files (jest.mock formatting cleanup)

Summary by CodeRabbit

  • 新增功能
    • 在验证选项中增加可选的帧延迟配置 delayFrame,控制验证是否在下一帧执行;依赖触发的字段验证默认启用帧延迟以避免即时执行。
  • 测试
    • 精简测试配置,移除对延迟工具的局部模拟,降低测试对该工具的耦合。

- Add delayFrame option to InternalValidateOptions interface
- Conditionally call delayFrame when delayFrame option is true in Field.validateRules
- Use delayFrame: true in triggerDependenciesUpdate to avoid useWatch rule timing issues
- Adjust test files (jest.mock formatting cleanup)
@vercel
Copy link

vercel bot commented Mar 4, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
field-form Ready Ready Preview, Comment Mar 4, 2026 7:15am

@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the form validation mechanism by introducing a delayFrame option. This option allows for validation to be deferred until after a browser frame render, which is crucial for scenarios involving useWatch hooks where dynamic rules might not have access to the most current values. The change improves the reliability of validation by ensuring that all dependencies are up-to-date before rules are evaluated.

Highlights

  • New delayFrame option: Introduced a delayFrame option to the InternalValidateOptions interface to control validation timing.
  • Conditional delayFrame execution: Modified Field.validateRules to conditionally call delayFrame when the new delayFrame option is enabled, ensuring validation occurs after a frame render.
  • Improved dependency validation timing: Utilized delayFrame: true within triggerDependenciesUpdate to address timing issues with useWatch rules, ensuring dependencies receive the latest values before validation.
  • Test file adjustments: Cleaned up jest.mock formatting in several test files for consistency.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • src/Field.tsx
    • Modified validateRules to accept and conditionally use the new delayFrame option.
  • src/hooks/useForm.ts
    • Updated triggerDependenciesUpdate to call validateFields with delayFrame: true.
  • src/interface.ts
    • Added delayFrame?: boolean to the InternalValidateOptions interface.
  • tests/index.test.tsx
    • Adjusted jest.mock import formatting.
  • tests/list.test.tsx
    • Adjusted jest.mock import formatting.
  • tests/validate-warning.test.tsx
    • Adjusted jest.mock import formatting.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link

coderabbitai bot commented Mar 4, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8280246f-7cfb-4f6b-9531-d19701e6850e

📥 Commits

Reviewing files that changed from the base of the PR and between 15f2539 and 7a40329.

📒 Files selected for processing (1)
  • tests/index.test.tsx
💤 Files with no reviewable changes (1)
  • tests/index.test.tsx

Walkthrough

本次更改引入可选的 delayFrame 验证标志:仅当该标志为真时才在 Field.tsx 中等待帧延迟;在表单依赖触发验证时通过 useForm 传入 delayFrame: true;并在接口中新增该可选属性,若干测试移除对延迟工具的 Jest mock。

Changes

Cohort / File(s) Summary
验证接口定义
src/interface.ts
InternalValidateOptions 添加可选布尔属性 delayFrame?: boolean,用于在内部验证选项上传递帧延迟开关。
字段验证逻辑
src/Field.tsx
解构并使用 delayFrame(别名 showDelayFrame),仅在标志为真时 await delayFrame(),避免默认强制异步帧延迟。
表单依赖更新
src/hooks/useForm.ts
triggerDependenciesUpdate 中对依赖字段调用 validateFields 时传入 delayFrame: true,使依赖触发的验证以帧延迟方式执行。
测试文件调整
tests/index.test.tsx, tests/list.test.tsx, tests/validate-warning.test.tsx, tests/context.test.tsx
移除对 ../src/utils/delayUtil 的 Jest mock 并清理相关导入;无功能性变更,仅调整测试环境。

Sequence Diagram(s)

sequenceDiagram
participant Trigger as "triggerDependenciesUpdate"
participant Validator as "validateFields"
participant Field as "Field.validate"
participant Rules as "Rule Evaluation"
participant Observer as "Observers"

Trigger->>Validator: validateFields(delayFrame: true)
Validator->>Field: 调用字段验证并传入 options
alt options.delayFrame === true
    Field->>Field: await delayFrame()
end
Field->>Rules: 评估规则(同步或异步)
Rules->>Observer: 更新验证结果
Observer-->>Trigger: 通知 / 继续依赖传播
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 分钟

Possibly related PRs

Suggested reviewers

  • crazyair

诗歌

🐰 验证帧可选轻轻开,
条件等待不再强制来,
依赖触发悄悄排,
代码微调心里哼,
胡萝卜跳跳庆佳改 🥕✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately describes the main change: adding a delayFrame option to validateFields, which is clearly reflected in the modifications to Field.tsx, useForm.ts, and the interface definition.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/delayFrame-option

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a delayFrame option for validateFields to address timing issues with useWatch during dependency updates. The implementation is sound, but I've identified a potential regression. By making the frame delay conditional, it's removed from most validation paths, which could break existing forms that rely on this delay. I've suggested a modification to make this change non-breaking while still allowing for performance optimizations.

Comment on lines +407 to +409
if (showDelayFrame) {
await delayFrame();
}

Choose a reason for hiding this comment

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

high

This change makes the delayFrame conditional. While this is useful for adding the new option, it changes the default behavior. Previously, await delayFrame() was called unconditionally, which helped prevent race conditions with useWatch in validation rules.

Now, the delay only occurs if delayFrame: true is explicitly passed. This removes the delay for standard validation triggers (like onChange) and manual form.validateFields() calls, which could be a regression for users relying on this behavior (e.g., calling validateFields immediately after a state change that useWatch depends on).

If the goal is to allow opting out of the delay for performance, rather than requiring an opt-in, I'd suggest keeping the delay by default to avoid a breaking change. This can be done by checking if showDelayFrame is not explicitly false.

This would maintain backward compatibility while still providing a path for performance optimization.

Suggested change
if (showDelayFrame) {
await delayFrame();
}
if (showDelayFrame !== false) {
await delayFrame();
}

The jest.mock('../src/utils/delayUtil') was removed from multiple test files since it's no longer needed after the delayFrame implementation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
tests/index.test.tsx (1)

4-4: ⚠️ Potential issue | 🔴 Critical

缺失类型导入导致测试编译失败。

文件中大量使用 FormRef(15+ 处)和 Meta(至少 1 处),但未导入这两个类型,直接触发编译错误。需在导入区添加这些类型。

🔧 建议修复
import React from 'react';
import type { FormInstance } from '../src';
+import type { FormRef, Meta } from '../src/interface';
import Form, { Field, useForm } from '../src';
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/index.test.tsx` at line 4, The tests fail to compile because the types
FormRef and Meta are used but not imported; update the type import statement
that currently imports FormInstance to also import FormRef and Meta (e.g.,
change the import line importing FormInstance to import type { FormInstance,
FormRef, Meta } from the same module) so all referenced types (FormRef and Meta)
are available to the tests.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@tests/index.test.tsx`:
- Line 4: The tests fail to compile because the types FormRef and Meta are used
but not imported; update the type import statement that currently imports
FormInstance to also import FormRef and Meta (e.g., change the import line
importing FormInstance to import type { FormInstance, FormRef, Meta } from the
same module) so all referenced types (FormRef and Meta) are available to the
tests.

ℹ️ Review info
Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6c204b9f-8bcb-4d25-bfa6-1fa436ad2062

📥 Commits

Reviewing files that changed from the base of the PR and between f914c41 and 0c8b4e5.

📒 Files selected for processing (6)
  • src/Field.tsx
  • src/hooks/useForm.ts
  • src/interface.ts
  • tests/index.test.tsx
  • tests/list.test.tsx
  • tests/validate-warning.test.tsx

@codecov
Copy link

codecov bot commented Mar 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.54%. Comparing base (f914c41) to head (7a40329).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #777   +/-   ##
=======================================
  Coverage   99.54%   99.54%           
=======================================
  Files          20       20           
  Lines        1324     1325    +1     
  Branches      329      309   -20     
=======================================
+ Hits         1318     1319    +1     
  Misses          6        6           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@zombieJ zombieJ merged commit ac021b3 into master Mar 4, 2026
13 checks passed
@zombieJ zombieJ deleted the feature/delayFrame-option branch March 4, 2026 07:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant