From 580377201793314ca643250c1bd7cf1c47d49920 Mon Sep 17 00:00:00 2001 From: Wen-Chien Chen Date: Tue, 30 Oct 2018 17:02:45 -0700 Subject: [PATCH] Wrap measureLayoutRelativeToContainingList in try-catch to mitigate crash Summary: This function sometimes causes an "Unable to find node on an unmounted component" crash during pagination for reasons that still need to be investigated; in the meanwhile, wrap this in a try-catch block to mitigate the crash. Reviewed By: sahrens Differential Revision: D12829971 fbshipit-source-id: bc9fe5b9b8c03430ff890bfbb27c39aa270c9eb7 --- Libraries/Lists/VirtualizedList.js | 56 ++++++++++++++++++------------ 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/Libraries/Lists/VirtualizedList.js b/Libraries/Lists/VirtualizedList.js index 05c15e8d48d8e7..37c574f0555530 100644 --- a/Libraries/Lists/VirtualizedList.js +++ b/Libraries/Lists/VirtualizedList.js @@ -1112,28 +1112,40 @@ class VirtualizedList extends React.PureComponent { }; measureLayoutRelativeToContainingList(): void { - UIManager.measureLayout( - ReactNative.findNodeHandle(this), - ReactNative.findNodeHandle( - this.context.virtualizedList.getOutermostParentListRef(), - ), - error => { - console.warn( - "VirtualizedList: Encountered an error while measuring a list's" + - ' offset from its containing VirtualizedList.', - ); - }, - (x, y, width, height) => { - this._offsetFromParentVirtualizedList = this._selectOffset({x, y}); - this._scrollMetrics.contentLength = this._selectLength({width, height}); - - const scrollMetrics = this._convertParentScrollMetrics( - this.context.virtualizedList.getScrollMetrics(), - ); - this._scrollMetrics.visibleLength = scrollMetrics.visibleLength; - this._scrollMetrics.offset = scrollMetrics.offset; - }, - ); + // TODO (T35574538): findNodeHandle sometimes crashes with "Unable to find + // node on an unmounted component" during scrolling + try { + UIManager.measureLayout( + ReactNative.findNodeHandle(this), + ReactNative.findNodeHandle( + this.context.virtualizedList.getOutermostParentListRef(), + ), + error => { + console.warn( + "VirtualizedList: Encountered an error while measuring a list's" + + ' offset from its containing VirtualizedList.', + ); + }, + (x, y, width, height) => { + this._offsetFromParentVirtualizedList = this._selectOffset({x, y}); + this._scrollMetrics.contentLength = this._selectLength({ + width, + height, + }); + + const scrollMetrics = this._convertParentScrollMetrics( + this.context.virtualizedList.getScrollMetrics(), + ); + this._scrollMetrics.visibleLength = scrollMetrics.visibleLength; + this._scrollMetrics.offset = scrollMetrics.offset; + }, + ); + } catch (error) { + console.warn( + 'measureLayoutRelativeToContainingList threw an error', + error.stack, + ); + } } _onLayout = (e: Object) => {