Permalink
Browse files

Work around a false positive warning

Summary:
This works around a false positive `isMounted()` deprecation warning when using latest React DevTools and selecting components in the hierarchy.

Before:

![screen shot 2017-05-09 at 7 03 39 pm 1](https://cloud.githubusercontent.com/assets/810438/25865249/3a5cc9e2-34ea-11e7-9930-6d0d8436b390.png)

After:

![screen shot 2017-05-09 at 7 02 54 pm](https://cloud.githubusercontent.com/assets/810438/25865274/4d2d573a-34ea-11e7-8bdd-807e32c54594.png)
Closes #13873

Reviewed By: bvaughn

Differential Revision: D5029550

Pulled By: gaearon

fbshipit-source-id: cbe941368e8204a335de17ad3d444580aef9d833
  • Loading branch information...
gaearon authored and facebook-github-bot committed May 9, 2017
1 parent 82fd02a commit 074c3cef145635bf647a6a1552305bb66916ef08
Showing with 16 additions and 4 deletions.
  1. +16 −4 Libraries/Renderer/src/renderers/native/NativeMethodsMixinUtils.js
@@ -57,12 +57,24 @@ export interface NativeMethodsInterface {
*/
function mountSafeCallback(context: any, callback: ?Function): any {
return function() {
if (
!callback ||
(typeof context.isMounted === 'function' && !context.isMounted())
) {
if (!callback) {
return undefined;
}
if (typeof context.__isMounted === 'boolean') {
// TODO(gaearon): this is gross and should be removed.
// It is currently necessary because View uses createClass,
// and so any measure() calls on View (which are done by React
// DevTools) trigger the isMounted() deprecation warning.
if (!context.__isMounted) {
return undefined;
}
// The else branch is important so that we don't
// trigger the deprecation warning by calling isMounted.
} else if (typeof context.isMounted === 'function') {
if (!context.isMounted()) {
return undefined;
}
}
return callback.apply(context, arguments);
};
}

0 comments on commit 074c3ce

Please sign in to comment.