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

UIP-2186 Don't call setState when AbstractTransitionComponent is unmounting #59

Merged

Conversation

joshbeam-wf
Copy link
Contributor

This resolves a warning of the form "Warning: setState(...): Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component. This is a no-op."

Ultimate problem:

An AbstractTransitionComponent's setState call to set the transition phase to TransitionPhase.HIDDEN can occur after the component has been unmounted. This may happen if the component contains a button that causes the AbstractTransitionComponent to be unmounted when clicked.

How it was fixed:

Added _isMounted boolean to the component to keep track of whether or not the component is mounted (it's set to true in componentDidMount and set to false in componentWillUnmount). The value of this boolean is checked before calling setState to set the transition phase to TransitionPhase.HIDDEN.

Testing suggestions:

Verify that tests pass.

Potential areas of regression:

Components based on AbstractTransitionComponent.


FYA: @greglittlefield-wf @aaronlademann-wf @jacehensley-wf @clairesarsam-wf @joelleibow-wf

This resolves a warning of the form "Warning: setState(...): Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component. This is a no-op."
@aviary-wf
Copy link

Raven

Number of Findings: 0

@codecov-io
Copy link

Codecov Report

Merging #59 into master will increase coverage by 0.01%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master      #59      +/-   ##
==========================================
+ Coverage   97.72%   97.72%   +0.01%     
==========================================
  Files          28       28              
  Lines        1356     1358       +2     
==========================================
+ Hits         1325     1327       +2     
  Misses         31       31

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 44acae5...b7a2bf4. Read the comment docs.

@greglittlefield-wf
Copy link
Contributor

  • Change and tests look great.
  • Tests pass.
  • No regressions found in transition-related behavior.

+10

Thanks for the contribution!

@rmconsole2-wf rmconsole2-wf changed the title Don't call setState when AbstractTransitionComponent is unmounting UIP-2186 Don't call setState when AbstractTransitionComponent is unmounting Mar 30, 2017
@jacehensley-wf
Copy link
Contributor

+1


@override
void componentDidMount() {
_isMounted = true;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this fall back to the antipattern of tracking mounts?

https://facebook.github.io/react/blog/2015/12/16/ismounted-antipattern.html

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No that is the isMounted method on a React component. They actually recommend this pattern:

"An easy migration strategy for anyone upgrading their code to avoid isMounted() is to track the mounted status yourself. Just set a _isMounted property to true in componentDidMount and set it to false in componentWillUnmount, and use this variable to check your component's status."

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. Just saw it and noticed.

@leviwith-wf
Copy link
Contributor

QA +1

  • Testing instruction
  • Dev +1's
  • Dev/QA +10
  • Unit tests created/updated
  • All unit tests pass
  • Rosie ran/Rosie comment displays expected info
  • Dependency Scan Clean

Merging.

@leviwith-wf leviwith-wf merged commit 1986adf into Workiva:master Mar 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants