Fixes 'Invalid render range' crash (#22847)
Summary: When a list is updated to have fewer items and the user immediately scrolls, the `ViewabilityHelper` `computeViewableItems` can be invoked from the scroll and cause a crash. This side effect *should* be relatively minor; the ViewabilityHelper shouldn't cause a crash, as it generally would be used for analytics to see what users are viewing. I suggest changing this to a warning instead of a crash. Other react-native developers seem to [also be getting this occasionally](https://github.com/facebook/react-native/issues/20289). Changelog: ---------- [General] [Fixed] - `Invalid render range` crash changed to warning when viewability helper detects an anomaly in list data. Pull Request resolved: https://github.com/facebook/react-native/pull/22847 Differential Revision: D13750031 Pulled By: cpojer fbshipit-source-id: 053d2baad208d1efe5b18b07ab10226032e665b8
This commit is contained in:
parent
9f64ba5b06
commit
e011c4c0e2
|
@ -121,10 +121,13 @@ class ViewabilityHelper {
|
|||
}
|
||||
let firstVisible = -1;
|
||||
const {first, last} = renderRange || {first: 0, last: itemCount - 1};
|
||||
invariant(
|
||||
last < itemCount,
|
||||
'Invalid render range ' + JSON.stringify({renderRange, itemCount}),
|
||||
);
|
||||
if (last >= itemCount) {
|
||||
console.warn(
|
||||
'Invalid render range computing viewability ' +
|
||||
JSON.stringify({renderRange, itemCount}),
|
||||
);
|
||||
return [];
|
||||
}
|
||||
for (let idx = first; idx <= last; idx++) {
|
||||
const metrics = getFrameMetrics(idx);
|
||||
if (!metrics) {
|
||||
|
|
Loading…
Reference in New Issue