diff --git a/uui-core/src/data/processing/views/tree/hooks/strategies/lazyTree/useLazyFetchingAdvisor.ts b/uui-core/src/data/processing/views/tree/hooks/strategies/lazyTree/useLazyFetchingAdvisor.ts index 15b846ed05..577460d321 100644 --- a/uui-core/src/data/processing/views/tree/hooks/strategies/lazyTree/useLazyFetchingAdvisor.ts +++ b/uui-core/src/data/processing/views/tree/hooks/strategies/lazyTree/useLazyFetchingAdvisor.ts @@ -3,6 +3,7 @@ import { usePrevious } from '../../../../../../../hooks/usePrevious'; import { DataSourceState } from '../../../../../../../types'; import { isQueryChanged } from './helpers'; import { useCallback, useMemo } from 'react'; +import { useDepsChanged } from '../../common/useDepsChanged'; export interface UseLazyFetchingAdvisorProps { dataSourceState: DataSourceState; @@ -12,13 +13,17 @@ export interface UseLazyFetchingAdvisorProps { showSelectedOnly?: boolean; } -export function useLazyFetchingAdvisor({ - dataSourceState, - filter, - forceReload, - backgroundReload, - showSelectedOnly, -}: UseLazyFetchingAdvisorProps) { +export function useLazyFetchingAdvisor( + { + dataSourceState, + filter, + forceReload, + backgroundReload, + showSelectedOnly, + }: UseLazyFetchingAdvisorProps, + deps: any[] = [], +) { + const depsChanged = useDepsChanged(deps); const areMoreRowsNeeded = useCallback(( prevValue?: DataSourceState, newValue?: DataSourceState, @@ -40,8 +45,9 @@ export function useLazyFetchingAdvisor({ || !isEqual(prevFilter, filter) || isQueryChanged(prevDataSourceState, dataSourceState) || (prevShowSelectedOnly !== showSelectedOnly && !showSelectedOnly) - || forceReload, - [dataSourceState, filter, forceReload], + || forceReload + || depsChanged, + [dataSourceState, filter, forceReload, depsChanged], ); const moreRowsNeeded = areMoreRowsNeeded(prevDataSourceState, dataSourceState); diff --git a/uui-core/src/data/processing/views/tree/hooks/strategies/lazyTree/useLazyTree.ts b/uui-core/src/data/processing/views/tree/hooks/strategies/lazyTree/useLazyTree.ts index b4fac7e56d..f407296332 100644 --- a/uui-core/src/data/processing/views/tree/hooks/strategies/lazyTree/useLazyTree.ts +++ b/uui-core/src/data/processing/views/tree/hooks/strategies/lazyTree/useLazyTree.ts @@ -94,7 +94,7 @@ export function useLazyTree( forceReload: isForceReload, backgroundReload, showSelectedOnly, - }); + }, [...deps]); useEffect(() => { if (showSelectedOnly && isSelectedOrCheckedChanged(dataSourceState, prevDataSourceState)) { diff --git a/uui-core/src/data/processing/views/tree/treeStructure/helpers/FetchingHelper.ts b/uui-core/src/data/processing/views/tree/treeStructure/helpers/FetchingHelper.ts index e18c550c6b..86904ba20f 100644 --- a/uui-core/src/data/processing/views/tree/treeStructure/helpers/FetchingHelper.ts +++ b/uui-core/src/data/processing/views/tree/treeStructure/helpers/FetchingHelper.ts @@ -280,7 +280,7 @@ export class FetchingHelper { remainingRowsCount = Number.MAX_SAFE_INTEGER; } - const missingCount = remainingRowsCount - ids.length; + const missingCount = Math.max(0, remainingRowsCount - ids.length); const availableCount = childrenCount != null ? childrenCount - ids.length : missingCount;