Skip to content

Commit

Permalink
Fix #6015: VirtualScroll emty items defensive check (#6017)
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware authored Feb 20, 2024
1 parent 008e592 commit 6cd5730
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions components/lib/virtualscroller/VirtualScroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ export const VirtualScroller = React.memo(
Promise.resolve().then(() => {
lazyLoadState.current = {
first: props.step ? (both ? { rows: 0, cols: firstState.cols } : 0) : firstState,
last: Math.min(props.step ? props.step : last, props.items.length)
last: Math.min(props.step ? props.step : last, (props.items || []).length)
};

props.onLazyLoad && props.onLazyLoad(lazyLoadState.current);
Expand Down Expand Up @@ -252,7 +252,7 @@ export const VirtualScroller = React.memo(
};

const getLast = (last = 0, isCols) => {
return props.items ? Math.min(isCols ? (props.columns || props.items[0]).length : props.items.length, last) : 0;
return props.items ? Math.min(isCols ? (props.columns || props.items[0])?.length || 0 : (props.items || []).length, last) : 0;
};

const getContentPosition = () => {
Expand Down Expand Up @@ -416,8 +416,8 @@ export const VirtualScroller = React.memo(

if (props.lazy && isPageChanged(first)) {
const newLazyLoadState = {
first: props.step ? Math.min(getPageByFirst(first) * props.step, props.items.length - props.step) : first,
last: Math.min(props.step ? (getPageByFirst(first) + 1) * props.step : last, props.items.length)
first: props.step ? Math.min(getPageByFirst(first) * props.step, (props.items || []).length - props.step) : first,
last: Math.min(props.step ? (getPageByFirst(first) + 1) * props.step : last, (props.items || []).length)
};

const isLazyStateChanged = !lazyLoadState.current || lazyLoadState.current.first !== newLazyLoadState.first || lazyLoadState.current.last !== newLazyLoadState.last;
Expand Down Expand Up @@ -496,7 +496,7 @@ export const VirtualScroller = React.memo(
};

const loaderOptions = (index, extOptions) => {
const count = loaderArrState.length;
const count = loaderArrState.length || 0;

return {
index,
Expand Down

0 comments on commit 6cd5730

Please sign in to comment.