From c489660f264859a10fc89e8f9bf091ead5d59e15 Mon Sep 17 00:00:00 2001 From: Edvin Erikson Date: Tue, 8 Dec 2015 10:09:16 -0800 Subject: [PATCH] Inspecting stateless components. Summary: Fixes #4602 Fixes a bug where the app crashes when you try to inspect a stateless component. Fixed by replacing all occurrences of the getPublicInstance method in Libraries/Inspector/Inspector.js with the _instance property instead. Defaults to an empty object if _instance is falsy. Closes https://github.com/facebook/react-native/pull/4642 Reviewed By: svcscm Differential Revision: D2734491 Pulled By: androidtrunkagent fb-gh-sync-id: 4ea753b7e0ef3fd05af2d80abadc365c5c787f98 --- Libraries/Inspector/Inspector.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Libraries/Inspector/Inspector.js b/Libraries/Inspector/Inspector.js index 7dbec7443..c72da8e7e 100644 --- a/Libraries/Inspector/Inspector.js +++ b/Libraries/Inspector/Inspector.js @@ -98,7 +98,9 @@ class Inspector extends React.Component { setSelection(i: number) { var instance = this.state.hierarchy[i]; - var publicInstance = instance.getPublicInstance(); + // if we inspect a stateless component we can't use the getPublicInstance method + // therefore we use the internal _instance property directly. + var publicInstance = instance._instance || {}; UIManager.measure(React.findNodeHandle(instance), (x, y, width, height, left, top) => { this.setState({ inspected: { @@ -115,7 +117,9 @@ class Inspector extends React.Component { this.state.devtoolsAgent.selectFromReactInstance(instance, true); } var hierarchy = InspectorUtils.getOwnerHierarchy(instance); - var publicInstance = instance.getPublicInstance(); + // if we inspect a stateless component we can't use the getPublicInstance method + // therefore we use the internal _instance property directly. + var publicInstance = instance._instance || {}; var props = publicInstance.props || {}; this.setState({ panelPos: pointerY > Dimensions.get('window').height / 2 ? 'top' : 'bottom',