RXNT / react-jsonschema-form-conditionals

react-jsonschema-form-conditionals

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bug: setState called after unmount

6uliver opened this issue · comments

After the form did unmount it is possible to run into the following warning:

Warning: Can't perform a React state update 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.

The reason is that FormWithConditionals updateConf method waited runRules Promise and then updates the state regardless the component is unmounted already.

The sequence of the events occuring this bug:

  1. FormWithConditionals mounts
  2. FormWithConditionals renders
  3. A change occurs, for example the form data has been changed
  4. updateConf triggers
  5. runRules starts
  6. FormWithConditionals gets unmounted for an external reason (for example it is conditionally rendered in other component)
  7. runRules promise gets resolved and calls setState