Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unmounted component setState fix #420

Merged
merged 2 commits into from
Mar 1, 2017
Merged

Conversation

alexeuler
Copy link
Contributor

@alexeuler alexeuler commented Jan 13, 2017

This code in TransitionMotion was a source of bug for us in testing.

    if (this.unmounting) {
        return;
    }
    // TODO: when config is {a: 10} and dest is {a: 10} do we raf once and
    // call cb? No, otherwise accidental parent rerender causes cb trigger
    this.animationID = defaultRaf((timestamp) => {
      const propStyles = this.props.styles;
      ...
      this.setState({
        currentStyles: newCurrentStyles,
        currentVelocities: newCurrentVelocities,
        lastIdealStyles: newLastIdealStyles,
        lastIdealVelocities: newLastIdealVelocities,
        mergedPropsStyles: newMergedPropsStyles,
      });
      ...
    }

The problem is that if execution passes the conditional if (this.unmounting), then executes async defaultRaf and after that component unmounts and after that the callback of defaultRaf is called, then setState will be called on unmounted component.

This fix solves the problem.

@chenglou
Copy link
Owner

Thanks. Wouldn't the right fix be having the check in both locations? This way we bail early instead of allocating another callback.

@alexeuler
Copy link
Contributor Author

@chenglou Done!

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

Successfully merging this pull request may close these issues.

2 participants