Skip to content

Commit da8ae01

Browse files
elicwhitefacebook-github-bot
authored andcommitted
Fix exception in scrollResponderScrollNativeHandleToKeyboard when ref is null
Summary: We are seeing these errors in prod: ``` TypeError: Cannot read property '_nativeTag' of null at ReactNativeFiberHostComponent.prototype.measureLayout(ReactNativeRenderer-prod.fb.js:1594) ScrollResponderMixin.scrollResponderScrollNativeHandleToKeyboard(ScrollResponder.js:557) ``` This error is coming from these lines: https://github.com/facebook/react-native/blob/69c38e5a639f34620038ae5724426c92c355e509/Libraries/Components/ScrollResponder.js#L563-L567 Either `nodeHandle` is null or `this.getInnerViewRef()`. If `nodeHandle` was null, we'd get an error that we can't call `measureLayout` on null. So `this.getInnerViewRef()` must be null. In the React Native Renderer this error of `_nativeTag of null` is coming from this line: https://github.com/facebook/react/blob/db8afe4f6318dba422177a2054204ef089570ad8/packages/react-native-renderer/src/ReactNativeFiberHostComponent.js#L84 Which means indeed `this.getInnerViewRef()` is null. So adding a null check here which is what we do at all the other product callsites of `measureLayout`. Flow should have caught this, but because ScrollView is one of the only components left using mixins (ScrollResponder), `this.getInnerViewRef` is typed as `any` instead of what it should be: ``` ?React.ElementRef<Class<ReactNative.NativeComponent<mixed>>> ``` If `scrollResponder` was typed correctly then Flow would have caught this. Changelog: [Fixed] Exception in scrollResponderScrollNativeHandleToKeyboard when ref is null Reviewed By: mmmulani Differential Revision: D17717150 fbshipit-source-id: d7bc4c897ad259fb588e8100f37ccfb8a5d07874
1 parent de20eb7 commit da8ae01

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Libraries/Components/ScrollResponder.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -560,8 +560,14 @@ const ScrollResponderMixin = {
560560
this.scrollResponderInputMeasureAndScrollToKeyboard,
561561
);
562562
} else {
563+
const innerRef = this.getInnerViewRef();
564+
565+
if (innerRef == null) {
566+
return;
567+
}
568+
563569
nodeHandle.measureLayout(
564-
this.getInnerViewRef(),
570+
innerRef,
565571
this.scrollResponderInputMeasureAndScrollToKeyboard,
566572
this.scrollResponderTextInputFocusError,
567573
);

0 commit comments

Comments
 (0)