Skip to content

Changes in 7.20.3 seem to cause useFieldArray changes to make all fields dirtyFields #7197

@dbousamra

Description

@dbousamra

Version Number

7.20.3

Codesandbox/Expo snack

https://codesandbox.io/s/react-hook-form-submit-only-dirty-fields-forked-o6yc4?file=/src/index.tsx

Steps to reproduce

If you append/remove a field array value, you will notice the dirty fields are a different format to what they were previously. Not such an issue, but this function:

const getDirtyValues = (
  dirtyFields: UnknownArrayOrObject | boolean,
  allValues: UnknownArrayOrObject,
): UnknownArrayOrObject => {
  // NOTE: Recursive function.

  // If *any* item in an array was modified, the entire array must be submitted, because there's no
  // way to indicate "placeholders" for unchanged elements. `dirtyFields` is `true` for leaves.
  if (dirtyFields === true || Array.isArray(dirtyFields)) {
    return allValues;
  }

  return Object.fromEntries(
    // @ts-ignore
    Object.keys(dirtyFields).map((key) => [key, getDirtyValues(dirtyFields[key], allValues[key])]),
  );
};

Which is floating around in an official example, and also this discussion: #1991

I spent ages trying to fix the function but I ran out of time.

Expected behaviour

I expect when I modify an array field, that the othern on array fields are not dirty

What browsers are you seeing the problem on?

No response

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions