react-redux-form
react-redux-form copied to clipboard
getForm doesn't return proper model for formReducer('') handling all forms - formValue is incorrect
The Problem
When formReducer handles all forms states (empty string as a model [just like here: https://davidkpiano.github.io/react-redux-form/docs/api/createForms.html]), <Form /> component's internal call of getForm (https://github.com/davidkpiano/react-redux-form/blob/master/src/components/form-component.js#L406) returns incorrect state.
It creates some errors when reading from $form state. For example: $form.intents, are never handled (memory leak), computing form-level validity is wrong and some others.
Steps to Reproduce
Create formReducer(''), that handles all forms states, check formValue of any <Form />.
Reproducible Code Example
https://codepen.io/marcinm2h/pen/GxjPrE
You can see in console formValue of <Form /> as it is logged in onUpdate handler.
Seems like you know a probable fix, want to open a PR?
I've found out that the problem occurs when I'm not passing initial state to formReducer(''), because initially state[formsReducerKey] doesn't have any sub-forms. Those are created on form actions.
Then this invalid formKey is cached, and later when I have state[formsReducerKey][subFormModel] in my state getFormStateKey(state, modelString, s) would compute it's model correctly, but it gets the incorrect one from cache/
I'm not sure if I should avoid cacheing on empty string model (''), or should just avoid initializing this kind of formReducer without initial state 🤔.
Edit: I'll try cacheing formStateKey for dynamic forms, when computed formStateKey's form model seems to be correct i.e. at least contains a part of getForm's argument model.