final-form / react-final-form

🏁 High performance subscription-based form state management for React
https://final-form.org/react
MIT License
7.39k stars 481 forks source link

[Bug] FormSpy render method called multiple times with different values #281

Open Mario-Eis opened 6 years ago

Mario-Eis commented 6 years ago

Are you submitting a bug report or a feature request?

Bug

What is the current behavior?

When initialValues on form changes, the FormSpy don't recognize this update any more. So the values in the FormSpys render function gets the previous initialValues as parameter. This was working correct in 3.6.1 but broke in 3.6.2

What is the expected behavior?

When intialValues of a form change, the FormSpy should also recognize this change and pass the new values to its render function.

Sandbox Link

What's your environment?

react 16.4.1 final form 4.8.2 react final form 3.6.2

Mario-Eis commented 6 years ago

I think this issues could be related to https://github.com/final-form/react-final-form/commit/a651c117cb1bfe448dfb1c11ebafa614ca285121

Is there a possibility to force a reinitialization if the initialValues change? Can this affect the FormSpy somehow?

Mario-Eis commented 6 years ago

Think i figured it out. The render method of the FormSpy now gets fired twice. First with the old data. Then with the new data. See https://codesandbox.io/s/w68mlx49kw In the sandbox the output seems correct. But in the console you can see, that the render function is called twice with different values. On EVERY update of the data. In my case thats an issue, because in the form there is a table rendered, passing the current row to the Field Components. These components are third party. So they cant use the name attribute. If the row count now won't match the actual data (because the data is received from the previous initialValues instead of the current ones), the render method will break.

Mario-Eis commented 6 years ago

Issue is still there in 3.6.5

Mario-Eis commented 6 years ago

Still in 3.6.6

micro-chipset commented 4 years ago

Still in 6.3.3