Skip to content

fix(form): stabilize ProForm/BaseForm renders and FormItem memoization#9605

Draft
chenshuai2144 wants to merge 1 commit intomasterfrom
cursor/form-review-performance-api-tests-964a
Draft

fix(form): stabilize ProForm/BaseForm renders and FormItem memoization#9605
chenshuai2144 wants to merge 1 commit intomasterfrom
cursor/form-review-performance-api-tests-964a

Conversation

@chenshuai2144
Copy link
Copy Markdown
Contributor

Summary

Form module review (performance, API shape, tests) and targeted fixes.

Performance

  • ProForm: The default contentRender was an inline function, so it was a new reference every parent re-render. That caused BaseForm’s content useMemo to recompute and remount the main form body unnecessarily. The default render is now a stable useCallback.
  • BaseForm: content’s useMemo now lists formRef (the ref object) instead of effectively depending on a stale formRef.current snapshot. useImperativeHandle for the extended formRef API no longer uses formRef.current in the dependency array (refs should not be read for dependency lists).

API / docs

  • Fixed a broken nested JSDoc on formatValues.validateFieldsReturnFormatValue in BaseForm (stray /** broke the block comment and hurt generated docs/IDE hints).

Tests

  • pnpm run tsc and pnpm exec vitest run tests/form (326 tests) pass.

Submitted by Cursor

Open in Web Open in Cursor 

…rativeHandle

- ProForm: memoize default contentRender with useCallback to avoid new
  function identity every render and unnecessary BaseForm content remounts
- BaseForm: fix nested JSDoc on formatValues; useImperativeHandle deps use
  formRef instead of formRef.current; content useMemo depends on formRef
- FormItem: useDeepCompareMemo depends on child fieldProps (not duplicate
  omit() in deps array) for correct deep-compare memoization

Co-authored-by: 陈帅 <wasd2144@hotmail.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 23, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 17cfea16-f8d7-4ee6-9c42-a8ccafb4efba

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cursor/form-review-performance-api-tests-964a

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
Copy Markdown
Contributor

@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 updates JSDoc comments, refactors dependency arrays in BaseForm and FormItem, and memoizes the contentRender function in ProForm. The review feedback points out a performance regression in FormItem due to improper dependency tracking in useDeepCompareMemo and identifies an unnecessary inclusion of a stable ref object in a useMemo dependency array in BaseForm.

['onBlur', 'onChange'],
),
],
[childFieldProps],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The change to the dependency array of omitOnBlurAndOnChangeProps introduces a performance regression. By using [childFieldProps] instead of the omitted object, the useDeepCompareMemo will now trigger a re-computation whenever onBlur or onChange change (which are often unstable inline functions in React forms). The previous implementation correctly ignored these event handlers by omitting them before the deep comparison, ensuring that only changes to other field props would trigger a re-render of the child component.

Suggested change
[childFieldProps],
[omit(childFieldProps || {}, ['onBlur', 'onChange'])],

}
return wrapItems;
}, [grid, RowWrapper, items, contentRender, submitterNode]);
}, [grid, RowWrapper, items, contentRender, submitterNode, formRef]);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Adding formRef to the dependency array of useMemo is unnecessary and potentially misleading. formRef is a ref object created via useRef within the component, so its reference is stable and will not trigger a re-computation of the memoized value. Furthermore, adding a ref object to dependencies does not solve "stale snapshot" issues because useMemo does not track changes to the .current property. If the intent is to ensure the latest form instance is used, accessing formRef.current inside the factory is sufficient, but it won't trigger updates if the ref is updated after the initial render.

Suggested change
}, [grid, RowWrapper, items, contentRender, submitterNode, formRef]);
}, [grid, RowWrapper, items, contentRender, submitterNode]);

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 23, 2026

Codecov Report

❌ Patch coverage is 83.33333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 88.48%. Comparing base (bdbf841) to head (dd22eaa).

Files with missing lines Patch % Lines
src/form/components/FormItem/index.tsx 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9605      +/-   ##
==========================================
- Coverage   88.53%   88.48%   -0.06%     
==========================================
  Files         368      368              
  Lines       11257    11259       +2     
  Branches     4157     4156       -1     
==========================================
- Hits         9966     9962       -4     
- Misses       1139     1144       +5     
- Partials      152      153       +1     

☔ 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.

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.

2 participants