Skip to content

RNTesterIntegrationTests can fail due to the warning "Can't call setState (or forceUpdate) on an unmounted component." #24984

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

Closed

Conversation

tom-un
Copy link
Contributor

@tom-un tom-un commented May 21, 2019

Summary

When running the RNTesterIntegrationTests from the XCode IDE or xcodebuild command line, its possible for tests to intermittently fail due to the 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.%s', '\n in RNTesterApp. .

A setState() call could happen in the AsyncStorage callback after the component had unmounted: presumably because the test ran and concluded before AsyncStorage returned. Changed RNTesterApp.ios.js to maintain a _mounted field that is set and cleared in componentDidMount() and componentWillUnmount() and refrain from calling setState() if the flag is false.

Changelog

[iOS] [Fixed] - Fixed RNTesterApp to not call setState() after the component has been unmounted.

Test Plan

All tests pass.

I have already made the same fix in the Microsoft fork of react-native: microsoft#18. The Microsoft Azure DevOps hosted CI loops also run RNTesterIntegrationTests. Before this fix we had only about an 86% pass rate and most of the failures were due to this warning. After this fix (and others) we are at a 98% pass rate.

tom-un added 2 commits May 21, 2019 10:53
…nd cleared in componentDidMount() and componentWillUnmount() and refrain from calling setState() if the flag is false

Changed RNTesterApp.ios.js to maintain a _mounted field that is set and cleared in componentDidMount() and componentWillUnmount() and refrain from calling setState() if the flag is false.
@facebook-github-bot
Copy link
Contributor

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@react-native-bot react-native-bot added Bug Platform: iOS iOS applications. labels May 21, 2019
@hramos hramos added p: Microsoft Partner: Microsoft Partner labels May 21, 2019
@hramos
Copy link
Contributor

hramos commented May 21, 2019

I emailed CLA@ to see if they can add you to the Microsoft CLA.

@react-native-bot react-native-bot added the No CLA Authors need to sign the CLA before a PR can be reviewed. label May 22, 2019
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label May 22, 2019
@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@react-native-bot react-native-bot removed the No CLA Authors need to sign the CLA before a PR can be reviewed. label May 22, 2019
Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@hramos is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@react-native-bot
Copy link
Collaborator

This pull request was successfully merged by @tom-un in 6671165.

When will my fix make it into a release? | Upcoming Releases

@react-native-bot react-native-bot added the Merged This PR has been merged. label May 22, 2019
vovkasm pushed a commit to vovkasm/react-native that referenced this pull request Aug 12, 2019
…tate (or forceUpdate) on an unmounted component." (facebook#24984)

Summary:
When running the RNTesterIntegrationTests from the XCode IDE or xcodebuild command line, its possible for tests to intermittently fail due to the 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.%s', '\n in RNTesterApp.` .

A setState() call could happen in the AsyncStorage callback after the component had unmounted: presumably because the test ran and concluded before AsyncStorage returned. Changed RNTesterApp.ios.js to maintain a _mounted field that is set and cleared in componentDidMount() and componentWillUnmount() and refrain from calling setState() if the flag is false.

## Changelog

[iOS] [Fixed] - Fixed RNTesterApp to not call setState() after the component has been unmounted.
Pull Request resolved: facebook#24984

Differential Revision: D15447898

Pulled By: hramos

fbshipit-source-id: b01bc0a40a4f4d548aca0a4bb891ba3f4c8d0612
(cherry picked from commit 6671165)
M-i-k-e-l pushed a commit to M-i-k-e-l/react-native that referenced this pull request Mar 10, 2020
…tate (or forceUpdate) on an unmounted component." (facebook#24984)

Summary:
When running the RNTesterIntegrationTests from the XCode IDE or xcodebuild command line, its possible for tests to intermittently fail due to the 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.%s', '\n in RNTesterApp.` .

A setState() call could happen in the AsyncStorage callback after the component had unmounted: presumably because the test ran and concluded before AsyncStorage returned. Changed RNTesterApp.ios.js to maintain a _mounted field that is set and cleared in componentDidMount() and componentWillUnmount() and refrain from calling setState() if the flag is false.

## Changelog

[iOS] [Fixed] - Fixed RNTesterApp to not call setState() after the component has been unmounted.
Pull Request resolved: facebook#24984

Differential Revision: D15447898

Pulled By: hramos

fbshipit-source-id: b01bc0a40a4f4d548aca0a4bb891ba3f4c8d0612
@tom-un tom-un deleted the tomun/FixRNTesterAppAsyncStorageRace branch May 8, 2020 21:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. p: Microsoft Partner: Microsoft Partner Platform: iOS iOS applications.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants