Repository navigation
fix(admin): use infinite scroll for content list to support large dat… - #135
Conversation
🦋 Changeset detectedLatest commit: 7a534ea The changes in this PR will be included in the next version bump. This PR includes changesets to release 10 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
All contributors have signed the CLA ✍️ ✅ |
There was a problem hiding this comment.
Pull request overview
Updates the admin content list route to use cursor-based pagination so collections with large numbers of items can load beyond the initial backend default page size.
Changes:
- Replace
useQuerywithuseInfiniteQueryfor the content list and wire cursor pagination vianextCursor. - Flatten
data.pagesinto a singleitemsarray for the existingContentListUI. - Connect
hasMore/onLoadMoreand treatisFetchingNextPageas loading so the “Load More” button reflects progress.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| queryKey: ["content", collection, { locale: activeLocale }], | ||
| queryFn: () => fetchContentList(collection, { locale: activeLocale }), | ||
| queryFn: ({ pageParam }) => | ||
| fetchContentList(collection, { locale: activeLocale, cursor: pageParam as string | undefined }), |
There was a problem hiding this comment.
fetchContentList supports a limit param, but this infinite query omits it, so the backend default (50, capped at 100) will be used. For large collections this increases the number of requests/clicks significantly; consider passing an explicit limit (e.g., 100) to reduce pagination overhead.
| fetchContentList(collection, { locale: activeLocale, cursor: pageParam as string | undefined }), | |
| fetchContentList(collection, { | |
| locale: activeLocale, | |
| cursor: pageParam as string | undefined, | |
| limit: 100, | |
| }), |
| queryFn: ({ pageParam }) => | ||
| fetchContentList(collection, { locale: activeLocale, cursor: pageParam as string | undefined }), | ||
| initialPageParam: undefined as string | undefined, | ||
| getNextPageParam: (lastPage) => lastPage.nextCursor, |
There was a problem hiding this comment.
This content list query runs even while manifest is still loading; when i18n is enabled, activeLocale changes from undefined to defaultLocale once the manifest arrives, which triggers an extra fetch under a different queryKey. Since the page renders a loading screen until manifest is available anyway, consider adding enabled: !!manifest (or gating on i18n resolution) to avoid the redundant request.
| getNextPageParam: (lastPage) => lastPage.nextCursor, | |
| getNextPageParam: (lastPage) => lastPage.nextCursor, | |
| enabled: !!manifest, |
|
I have read the CLA Document and I hereby sign the CLA |
@emdash-cms/admin
@emdash-cms/auth
@emdash-cms/blocks
@emdash-cms/cloudflare
emdash
create-emdash
@emdash-cms/gutenberg-to-portable-text
@emdash-cms/x402
@emdash-cms/plugin-ai-moderation
@emdash-cms/plugin-atproto
@emdash-cms/plugin-audit-log
@emdash-cms/plugin-color
@emdash-cms/plugin-embeds
@emdash-cms/plugin-forms
@emdash-cms/plugin-webhook-notifier
commit: |
|
recheck |
|
Thank you! |
Address Copilot review feedback (PR emdash-cms#996 review): the previous patch passed `isLoading || isFetchingNextPage` through to the loading-state branch, so clicking "Load More" temporarily blanked out the entire grid into a centered spinner before the next page arrived. Follow the same fix recipe used by ContentList in emdash-cms#135: gate the full-area loader on items.length === 0 so the spinner only renders during the *initial* fetch. While paginating, already-rendered items stay in place — keeping the user's scroll position and selection. Applied symmetrically to MediaLibrary and MediaPickerModal. Adds one regression test per component for the load-more-with-items case.
…braries (#996) * fix(admin): use infinite scroll for media library to support large libraries Mirror the content list fix from #135 for the media library admin page. Previously `MediaPage` called `fetchMediaList()` with no arguments, so the backend defaulted to limit=50 and the library only ever showed the first 50 items. The cursor pagination in the media repository was already implemented but the admin never used it. This wires `MediaPage` to `useInfiniteQuery` with `limit: 100` per page and adds `hasMore` / `onLoadMore` props to `MediaLibrary` so a "Load More" button appears when more items are available (local provider only; external providers continue to manage their own pagination internally). * fix(admin): paginate media picker modal too The same 50-item ceiling existed in MediaPickerModal (used by the rich text editor and image fields when embedding media into content): the modal hardcoded `limit: 50` on a single useQuery call with no Load More UI, so users could only ever pick from the most recent 50 items. - Switch the local-library query to useInfiniteQuery with limit: 100 - Update the dimensions mutation's setQueryData to walk every infinite page rather than the legacy `{ items, nextCursor }` shape - Render a Load More button under the picker grid (local provider only; external providers continue to manage pagination internally) - Add 3 tests covering the Load More button visibility and click flow * fix(admin): keep media items visible during Load More fetch Address Copilot review feedback (PR #996 review): the previous patch passed `isLoading || isFetchingNextPage` through to the loading-state branch, so clicking "Load More" temporarily blanked out the entire grid into a centered spinner before the next page arrived. Follow the same fix recipe used by ContentList in #135: gate the full-area loader on items.length === 0 so the spinner only renders during the *initial* fetch. While paginating, already-rendered items stay in place — keeping the user's scroll position and selection. Applied symmetrically to MediaLibrary and MediaPickerModal. Adds one regression test per component for the load-more-with-items case.
What does this PR do?
Closes #129
The admin content list previously only fetched the first 50 items because it was using a standard
useQueryquery without cursor pagination. For sites with a large number of content items, the vast majority were completely hidden because the "Load More" functionality wasn't properly wired up in the route layer.This PR wires up
useInfiniteQueryin the router (packages/admin/src/router.tsx) to pull in pages sequentially. Theitemsarray is flattened from all fetched pages, and the existinghasMoreandonLoadMoreprops on the ContentList component are connected. It also ensures theisLoadingstate is active whileisFetchingNextPageis true so the "Load More" button shows loading text properly.Type of change
Checklist
pnpm typecheckpassespnpm --silent lint:json | jq '.diagnostics | length'returns 0pnpm testpasses (or targeted tests for my change)pnpm formathas been runAI-generated code disclosure