Skip to content

issue: useFieldArray triggers extra re-render after reset #13577

Description

@BrendanC23

Version Number

7.80

Codesandbox/Expo snack

https://codesandbox.io/p/devbox/rhf-subscribe-clearerrors-forked-slgmgy

Steps to reproduce

  1. Click "reset". See that the Watch component is re-rendered twice.
  2. Comment out the useFieldArray line. Refresh the CSB and click "reset" again. Now, the component only re-renders once.

Expected behaviour

Clicking the reset button should only cause a single re-render. The presence or absence of useFieldArray should not change the rendering behavior.


The issue here seems to be that reset() notifies all subscribers once, and then useFieldArray notifies subscribers a second time (because the fields change triggers the useEffect.

_subjects.array.next({
values: { ...values },
});

control._subjects.state.next({
name,
values: cloneObject(control._formValues) as TFieldValues,
});

What browsers are you seeing the problem on?

Chrome

Relevant log output

Rendered: 1
Rendered: 2

Calling reset()
Rendered: 3
Rendered: 4

Code of Conduct

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions