NewOldMax / react-form-validator-core

Core validator component for react forms
MIT License
95 stars 44 forks source link

Memory leak with debounceTime #27

Closed okozlovskyi-nix closed 6 years ago

okozlovskyi-nix commented 6 years ago

I have next warning when I am using debounceTime, Warning: Can't call setState (or forceUpdate) on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method

my code:

<ValidatorForm
   onSubmit={this.handleSubmit}
  debounceTime={1000}
  ref={this.form}
>

When I am typing something in validation input and then I change route or close form component I always get this Warning, without debounceTime everything works correctly, but I need debounceTime. As I understand we need unsubscribe from debounceTime before component will unmaunt, but how can I handle it?

Please help me if you can

NewOldMax commented 6 years ago

Hi can you reproduce your issue here?

okozlovskyi-nix commented 6 years ago

Hi, I reproduced it here: https://codesandbox.io/s/0p92j9wx7p, I set debounceTime={3000}, you just need typing in email field and then just toggle form, and you will see in console next warning:

Warning: Can't call setState (or forceUpdate) on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method. in TextValidator (created by MyForm) in form (created by ValidatorForm) in ValidatorForm (created by MyForm) in MyForm (created by WithStyles(MyForm)) in WithStyles(MyForm) (created by App)

NewOldMax commented 6 years ago

Thanks, I see the problem. Will try to fix it later. Or you can do a PR if you have a solution already

NewOldMax commented 6 years ago

Fixed in 0.5.0

okozlovskyi-nix commented 6 years ago

Thanks!!!

On Thu, Sep 20, 2018 at 11:09 AM, NewOldMax notifications@github.com wrote:

Closed #27 https://github.com/NewOldMax/react-form-validator-core/issues/27.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/NewOldMax/react-form-validator-core/issues/27#event-1856966578, or mute the thread https://github.com/notifications/unsubscribe-auth/AmYMXZsN6UFKkA8ElWtPhhlXuEQJoDrrks5uc00hgaJpZM4WBv-y .

-- OLEH KOZLOVSKYI Software Engineer

Cell: +380-96-875-83-64 Email: okozlovskyi@n-ix.com Skype: oleg_master333 Lviv, Ukraine GMT+2, GMT+3 on DST www.n-ix.com

-- Confidentiality Note:  This e-mail and any attachments are confidential and may be protected by legal privilege. If you are not the intended recipient, be aware that any disclosure, copying, distribution or use of this e-mail or any attachment is prohibited. If you have received this e-mail in error, please notify us immediately by returning it to the sender and delete this copy from your system. Thank you for your cooperation.