Skip to content
This repository has been archived by the owner on Aug 23, 2022. It is now read-only.

Control component model values with 'debounce' defined are not resetting on actions.reset #884

Closed
lstuartfry opened this issue Jul 17, 2017 · 4 comments

Comments

@lstuartfry
Copy link

The Problem

When building a Control component and defining a 'debounce' prop, that component's model value is not reset when calling actions.reset on the form model. This is most likely related to the changes released with version 1.11.2, in relation to the 'debounce' prop. It looks like this change was added in relation to issue #799. The problem is, even if the debounced actions.change action has already finished updating the form, it will run again immediately after the component is unmounted.

Steps to Reproduce

Simply mount a form with a single Control component, and define a 'debounce' prop on the component. In componentWillUnmount, call an actions.reset on the form. Enter any value in the field, and unmount the form. First, the actions.reset call occurs, followed immediately by an actions.change call that restores the model to it's previous value.

Expected Behavior

The model's value will be restored to it's original value, defined wherever you chose to write its initialFormState.

Actual Behavior

The model is first reset to it's initial value, then restored to whichever value it held when the last debounced actions.change call was made.

Reproducible Code Example

(please fork from this CodePen template)
My CodePen example implements a simple button that switches between two forms. Each form calls actions.reset on its respective model on componentWillUnmount.
Please note - when I revert to version 1.11.1 or earlier, this problem does not occur. Also, I'd be more than happy to take a look at the source code and start working on a solution that satisfies both issue #799 and this new unexpected behavior.

@lstuartfry lstuartfry changed the title Control component values with 'debounce' defined are not resetting on actions.reset Control component model values with 'debounce' defined are not resetting on actions.reset Jul 17, 2017
@lstuartfry
Copy link
Author

Looks great, thanks!

@davidchase
Copy link

Hi guys,

Unless i am missing something this issue is still happening in current version 1.14.1, if you refer to the original code pen from the OP you can see it references the latest version of react-redux-form and calls reset and then change.

Please let me know.

Thanks

@lstuartfry
Copy link
Author

I can confirm, this is still an issue with the latest version(s) of react-redux-form.

@davidchase
Copy link

My current work around is to use debounce from lodash and use changeAction to customize the change handling all as a HOC but i guess it would be nice to have it work in the library as well 🙂

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants