Skip to content

Conversation

fzaninotto
Copy link
Member

@fzaninotto fzaninotto commented Sep 8, 2025

Problem

The way useApplyDefaultValues and ArrayInput subscribe to the form context to check for dirty or error state force a full rerendering of all fields in a field array on each change. This is very harmful for performance.

Solution

react-hook-form v7.62.0 introduces a way to subscribe to form changes without triggering a rerender. We can therefore manage the dirty and error states by hand to avoid the rerender.

How to test

Open the console, change the value of one field. Only this field should rerender

Open the React profiler, update one value in the array input, check out the output: no rendering should rerender all fields.

Also check that the NumberInput works as expected (it passes a null value when empty):

## Problem

The way useApplyDefaultValues and ArrayInput subscribe to the form context to check for dirty or error state force a full rerendering of all fields in a field array on each change. This is very harmful for performance.

## Solution

react-hook-form v7.62.0 introduces a way to subscribe to form changes without triggering a rerender. We can therefore manage the dirty and error states by hand to avoid the rerender.
@djhi
Copy link
Collaborator

djhi commented Sep 9, 2025

For now, we're stuck until react-hook-form/react-hook-form#12815 is solved

@fzaninotto fzaninotto changed the title Speed up ArrayInput [blocked] Speed up ArrayInput Sep 9, 2025
@djhi djhi changed the title [blocked] Speed up ArrayInput Speed up ArrayInput Oct 20, 2025
@djhi djhi added RFR Ready For Review and removed WIP Work In Progress labels Oct 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

RFR Ready For Review

Development

Successfully merging this pull request may close these issues.

2 participants