-
Notifications
You must be signed in to change notification settings - Fork 24.6k
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
Conversation
…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.
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! |
I emailed CLA@ to see if they can add you to the Microsoft CLA. |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
There was a problem hiding this 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.
This pull request was successfully merged by @tom-un in 6671165. When will my fix make it into a release? | Upcoming Releases |
…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)
…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
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.