From d7e7b3ef509a047ae27e9bea131a444f0bfcc35a Mon Sep 17 00:00:00 2001 From: Bartol Karuza Date: Wed, 20 Mar 2019 01:38:03 -0700 Subject: [PATCH] Fix #24053 prevent division by zero error in VirtualizedList debug overlay (#24058) Summary: This PR fixes the case where the content a VirtualizedList loads with a contentLength of 0, causing a crash in the `renderDebugOverlay` function. The result of that crash is a red screen when turning on debug on FlatList and other VirtualizedList components as described in #24053. [LIST] [FIX] - Fix VirtualizedList debug mode crash Pull Request resolved: https://github.com/facebook/react-native/pull/24058 Differential Revision: D14538317 Pulled By: cpojer fbshipit-source-id: 7b17bf51c388561c517bab1f775a31200abdc5a9 --- Libraries/Lists/VirtualizedList.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Libraries/Lists/VirtualizedList.js b/Libraries/Lists/VirtualizedList.js index 8455c51d616..f0ca4054f1c 100644 --- a/Libraries/Lists/VirtualizedList.js +++ b/Libraries/Lists/VirtualizedList.js @@ -1181,7 +1181,8 @@ class VirtualizedList extends React.PureComponent { _renderDebugOverlay() { const normalize = - this._scrollMetrics.visibleLength / this._scrollMetrics.contentLength; + this._scrollMetrics.visibleLength / + (this._scrollMetrics.contentLength || 1); const framesInLayout = []; const itemCount = this.props.getItemCount(this.props.data); for (let ii = 0; ii < itemCount; ii++) {