react-component / react-component/field-form

Field with dependencies is not rerendered when dependent field finishes validation

Open
#318 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
1k
Forks
286
Avg merge
4d 16h
Merged PRs (30d)
1

Description

In the following example, editing the username field will update the dependant field value but not the errors.

<Form>
  <Field name="username" rules=[{ required: true }]}>
    <Input />
  </Field>
         
  <Field dependencies={["username"]}>
    {(controls, meta, context) => (
      <div>
        <div>Value: {context.getFieldValue("username") || "null"}</div>
        <div>Errors: {context.getFieldError("username").join(", ")}</div>
      </div>
    )}
  </Field>
<Form>

Reproduction: https://codesandbox.io/s/antd-reproduction-template-forked-5ux1r?file=/index.js

The same behavior can only be achieved via a shouldUpdate={true} as using a custom shouldUpdate where we only compare the previous and current values of the username field would not work as value would be the same when info.type="validationFinish" triggers. Using shouldUpdate={true} is undesirable given the performance implications. Another option would be to add further information the 3rd parameter passed to shouldUpdate so the user can better choose when to rerender.

The above is the simplified use case. The real use case is to extract the form's item errors and render them via a custom component.

Related to https://github.com/ant-design/ant-design/issues/26888.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked CodeSandbox reproduction in index.js, then trace how Form and Field dependencies handle validation finishing. Done means a dependent field rerenders to show updated errors without requiring shouldUpdate={true}, while avoiding the broad performance cost described in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.