Skip to content

Commit

Permalink
Wrap measureLayoutRelativeToContainingList in try-catch to mitigate c…
Browse files Browse the repository at this point in the history
…rash

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
  • Loading branch information
Wen-Chien Chen authored and facebook-github-bot committed Oct 31, 2018
1 parent 811a99c commit 5803772
Showing 1 changed file with 34 additions and 22 deletions.
56 changes: 34 additions & 22 deletions Libraries/Lists/VirtualizedList.js
Original file line number Diff line number Diff line change
Expand Up @@ -1112,28 +1112,40 @@ class VirtualizedList extends React.PureComponent<Props, State> {
};

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) => {
Expand Down

0 comments on commit 5803772

Please sign in to comment.