Are you submitting a bug report or a feature request?
Bug Report
What is the current behavior?
When unregistering/re-registering a field on a form that is subscribed to pristine, the pristine value provided by FormRenderProps is different from the "true" pristine value in formState.
make changes to the "Click Swap after edit" input ONLY
click the swap button
observe the prop pristine value(true) is different from the real pristine value(false) (indicated by the submit button being greyed, also printed below)
What is the expected behavior?
Expect the latest pristine value passed as a FormRenderProp to equal the true pristine value in formState, as we are subscribed to pristine
Ran into this issue when we had 2 mutually exclusive components to deal with a single field, this problem would pop up when switching between the two if no other field is touched. This issue can be troublesome if you're only subscribed to pristine, since the form won't re-render until the pristine value changes again. In the example above, after clicking swap, even changing the unrelated field won't do anything, because the internal state already has pristine: false, so it won't re-render.
A workaround is to keep the field constantly registered somewhere else on the form. When you unregister a field, it's no longer taken into account for pristine calculations, so thats probably whats causing the pristine value to flip back to true in the first place. However, re-registering it with the same value does seem to trigger another pristine calculation, but it isn't causing a re-render the second time.
Are you submitting a bug report or a feature request?
Bug Report
What is the current behavior?
When unregistering/re-registering a field on a form that is subscribed to pristine, the pristine value provided by FormRenderProps is different from the "true" pristine value in formState.
sandbox link: https://codesandbox.io/s/react-final-form-simple-example-forked-q8p7o?file=/index.js
steps to reproduce:
What is the expected behavior?
Expect the latest pristine value passed as a FormRenderProp to equal the true pristine value in formState, as we are subscribed to pristine
Sandbox Link
https://codesandbox.io/s/react-final-form-simple-example-forked-q8p7o?file=/index.js
What's your environment?
Other information
Ran into this issue when we had 2 mutually exclusive components to deal with a single field, this problem would pop up when switching between the two if no other field is touched. This issue can be troublesome if you're only subscribed to pristine, since the form won't re-render until the pristine value changes again. In the example above, after clicking swap, even changing the unrelated field won't do anything, because the internal state already has pristine: false, so it won't re-render.
A workaround is to keep the field constantly registered somewhere else on the form. When you unregister a field, it's no longer taken into account for pristine calculations, so thats probably whats causing the pristine value to flip back to true in the first place. However, re-registering it with the same value does seem to trigger another pristine calculation, but it isn't causing a re-render the second time.