Skip to content

Commit 5803772

Browse files
Wen-Chien Chenfacebook-github-bot
Wen-Chien Chen
authored andcommitted
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
1 parent 811a99c commit 5803772

File tree

1 file changed

+34
-22
lines changed

1 file changed

+34
-22
lines changed

Libraries/Lists/VirtualizedList.js

+34-22
Original file line numberDiff line numberDiff line change
@@ -1112,28 +1112,40 @@ class VirtualizedList extends React.PureComponent<Props, State> {
11121112
};
11131113

11141114
measureLayoutRelativeToContainingList(): void {
1115-
UIManager.measureLayout(
1116-
ReactNative.findNodeHandle(this),
1117-
ReactNative.findNodeHandle(
1118-
this.context.virtualizedList.getOutermostParentListRef(),
1119-
),
1120-
error => {
1121-
console.warn(
1122-
"VirtualizedList: Encountered an error while measuring a list's" +
1123-
' offset from its containing VirtualizedList.',
1124-
);
1125-
},
1126-
(x, y, width, height) => {
1127-
this._offsetFromParentVirtualizedList = this._selectOffset({x, y});
1128-
this._scrollMetrics.contentLength = this._selectLength({width, height});
1129-
1130-
const scrollMetrics = this._convertParentScrollMetrics(
1131-
this.context.virtualizedList.getScrollMetrics(),
1132-
);
1133-
this._scrollMetrics.visibleLength = scrollMetrics.visibleLength;
1134-
this._scrollMetrics.offset = scrollMetrics.offset;
1135-
},
1136-
);
1115+
// TODO (T35574538): findNodeHandle sometimes crashes with "Unable to find
1116+
// node on an unmounted component" during scrolling
1117+
try {
1118+
UIManager.measureLayout(
1119+
ReactNative.findNodeHandle(this),
1120+
ReactNative.findNodeHandle(
1121+
this.context.virtualizedList.getOutermostParentListRef(),
1122+
),
1123+
error => {
1124+
console.warn(
1125+
"VirtualizedList: Encountered an error while measuring a list's" +
1126+
' offset from its containing VirtualizedList.',
1127+
);
1128+
},
1129+
(x, y, width, height) => {
1130+
this._offsetFromParentVirtualizedList = this._selectOffset({x, y});
1131+
this._scrollMetrics.contentLength = this._selectLength({
1132+
width,
1133+
height,
1134+
});
1135+
1136+
const scrollMetrics = this._convertParentScrollMetrics(
1137+
this.context.virtualizedList.getScrollMetrics(),
1138+
);
1139+
this._scrollMetrics.visibleLength = scrollMetrics.visibleLength;
1140+
this._scrollMetrics.offset = scrollMetrics.offset;
1141+
},
1142+
);
1143+
} catch (error) {
1144+
console.warn(
1145+
'measureLayoutRelativeToContainingList threw an error',
1146+
error.stack,
1147+
);
1148+
}
11371149
}
11381150

11391151
_onLayout = (e: Object) => {

0 commit comments

Comments
 (0)