From 524fc262cce191e84c424658beab77f981d8cbfe Mon Sep 17 00:00:00 2001 From: Marco Falkenberg Date: Fri, 15 Nov 2024 17:44:35 +0100 Subject: [PATCH] fix(List): fix initial loading also visible on reload --- .../List/model/loading/IncrementalLoader.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/components/src/components/List/model/loading/IncrementalLoader.ts b/packages/components/src/components/List/model/loading/IncrementalLoader.ts index e4053522c..230f366cb 100644 --- a/packages/components/src/components/List/model/loading/IncrementalLoader.ts +++ b/packages/components/src/components/List/model/loading/IncrementalLoader.ts @@ -12,6 +12,8 @@ import { times } from "remeda"; import { IncrementalLoaderState } from "@/components/List/model/loading/IncrementalLoaderState"; import { hash } from "object-code"; +type AsyncResourceLoadingState = AsyncResource["state"]["value"]; + const emptyData: never[] = []; export class IncrementalLoader { @@ -97,14 +99,26 @@ export class IncrementalLoader { asyncResource: AsyncResource>, batchIndex: number, ): void { + const skipReloadState = ( + newState: AsyncResourceLoadingState, + ): AsyncResourceLoadingState => { + if (this.loaderState.dataBatches[batchIndex]?.length > 0) { + return "loaded"; + } + return newState; + }; + useEffect(() => { this.loaderState.setBatchLoadingState( batchIndex, - asyncResource.state.value, + skipReloadState(asyncResource.state.value), ); return asyncResource.state.observe((newState) => { - this.loaderState.setBatchLoadingState(batchIndex, newState); + this.loaderState.setBatchLoadingState( + batchIndex, + skipReloadState(newState), + ); }); }, [asyncResource, batchIndex]); }