From c3f17de75ac38b1445c7cbf2bd178c68eea09c30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rge=20N=C3=A6ss?= Date: Fri, 27 Sep 2024 16:19:37 +0200 Subject: [PATCH] fixup! fix(structure): memoize search query results --- .../src/structure/panes/documentList/useDocumentList.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/sanity/src/structure/panes/documentList/useDocumentList.ts b/packages/sanity/src/structure/panes/documentList/useDocumentList.ts index 639ef804683..320b31dc8cf 100644 --- a/packages/sanity/src/structure/panes/documentList/useDocumentList.ts +++ b/packages/sanity/src/structure/panes/documentList/useDocumentList.ts @@ -8,6 +8,7 @@ import { map, mergeMap, scan, + share, shareReplay, take, takeUntil, @@ -21,7 +22,7 @@ import { useWorkspace, } from 'sanity' -import {DEFAULT_ORDERING, PARTIAL_PAGE_LIMIT} from './constants' +import {DEFAULT_ORDERING, FULL_LIST_LIMIT, PARTIAL_PAGE_LIMIT} from './constants' import {findStaticTypesInFilter, removePublishedWithDrafts} from './helpers' import {listenSearchQuery} from './listenSearchQuery' import {type DocumentListPaneItem, type SortOrder} from './types' @@ -92,7 +93,7 @@ export function useDocumentList(opts: UseDocumentListOpts): UseDocumentListHookV } const partialList$ = listenSearchQuery(listenSearchQueryArgs).pipe( - shareReplay({bufferSize: 1, refCount: true}), + shareReplay({refCount: true, bufferSize: 1}), ) // we want to fetch the full list if the last result of the partial list is at the limit @@ -104,12 +105,12 @@ export function useDocumentList(opts: UseDocumentListOpts): UseDocumentListHookV mergeMap(() => concat( of({type: 'loadFullList' as const}), - listenSearchQuery({...listenSearchQueryArgs, limit: PARTIAL_PAGE_LIMIT}).pipe( + listenSearchQuery({...listenSearchQueryArgs, limit: FULL_LIST_LIMIT}).pipe( map((result) => ({type: 'result' as const, result})), ), ), ), - shareReplay({bufferSize: 1, refCount: true}), + share(), ) // The combined search results from both partial page and full list