final-form / react-final-form-arrays

A component for rendering and editing arrays 🏁 React Final Form
MIT License
204 stars 69 forks source link

FieldArray becomes permanently dirty on change #37

Open anant-singh opened 6 years ago

anant-singh commented 6 years ago

Are you submitting a bug report or a feature request?

Bug

What is the current behavior?

If I change any field in a FieldArray, the state of the parent FieldArray changes to dirty and stays dirty even after reverting to the original state.

What is the expected behavior?

The top level FieldArray should revert to pristine state if the fields are returned to their original state.

Sandbox Link

I'd be happy to provide one if needed.

What's your environment?

Other information

https://github.com/final-form/react-final-form-arrays/blob/master/src/FieldArray.js#L78

Looking at where the FieldArray is registered, I see there is no equality comparator passed which would mean it defaults to a === check which would fail for an array.

I added a small snippet to enable addition of custom field level comparator to compare the arrays in my fork here: https://github.com/anant-singh/react-final-form-arrays/blob/dirty-field-check/src/FieldArray.js#L69-L88

JasonTheAdams commented 4 years ago

We are having an issue with this as well. This bug is very old. Any intentions to fix this @erikras?

JasonTheAdams commented 4 years ago

I'm really wondering if this is related to https://github.com/final-form/react-final-form/issues/709 wherein the underlying useField hook is no longer providing updated meta for sub-fields. The issue is regarding meta.active, but it's actually all meta data.