Skip to content

fix(admin): use infinite scroll for content list to support large dat… - #135

Merged
ascorbic merged 2 commits into
emdash-cms:mainfrom
fzihak:fix/issue-129
Apr 4, 2026
Merged

ascorbic merged 2 commits into
emdash-cms:mainfrom
fzihak:fix/issue-129

Conversation

@fzihak

@fzihak fzihak commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Closes #129

The admin content list previously only fetched the first 50 items because it was using a standard useQuery query 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 useInfiniteQuery in the router (packages/admin/src/router.tsx) to pull in pages sequentially. The items array is flattened from all fetched pages, and the existing hasMore and onLoadMore props on the ContentList component are connected. It also ensures the isLoading state is active while isFetchingNextPage is true so the "Load More" button shows loading text properly.

Type of change

  • Bug fix
  • Feature (requires approved Discussion)
  • Refactor (no behavior change)
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

  • I have read CONTRIBUTING.md
  • pnpm typecheck passes
  • pnpm --silent lint:json | jq '.diagnostics | length' returns 0
  • pnpm test passes (or targeted tests for my change)
  • pnpm format has been run
  • I have added/updated tests for my changes (if applicable)

AI-generated code disclosure

  • This PR includes AI-generated code

Copilot AI review requested due to automatic review settings April 2, 2026 21:27
@changeset-bot

changeset-bot Bot commented Apr 2, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7a534ea

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 10 packages
Name Type
@emdash-cms/admin Patch
emdash Patch
@emdash-cms/cloudflare Patch
@emdash-cms/plugin-ai-moderation Patch
@emdash-cms/plugin-atproto Patch
@emdash-cms/plugin-audit-log Patch
@emdash-cms/plugin-color Patch
@emdash-cms/plugin-embeds Patch
@emdash-cms/plugin-forms Patch
@emdash-cms/plugin-webhook-notifier Patch

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

@github-actions

github-actions Bot commented Apr 2, 2026 •

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 useQuery with useInfiniteQuery for the content list and wire cursor pagination via nextCursor.
  • Flatten data.pages into a single items array for the existing ContentList UI.
  • Connect hasMore / onLoadMore and treat isFetchingNextPage as loading so the “Load More” button reflects progress.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/admin/src/router.tsx Outdated
queryKey: ["content", collection, { locale: activeLocale }],
queryFn: () => fetchContentList(collection, { locale: activeLocale }),
queryFn: ({ pageParam }) =>
fetchContentList(collection, { locale: activeLocale, cursor: pageParam as string | undefined }),

Copilot AI Apr 2, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
fetchContentList(collection, { locale: activeLocale, cursor: pageParam as string | undefined }),
fetchContentList(collection, {
locale: activeLocale,
cursor: pageParam as string | undefined,
limit: 100,
}),

Copilot uses AI. Check for mistakes.
queryFn: ({ pageParam }) =>
fetchContentList(collection, { locale: activeLocale, cursor: pageParam as string | undefined }),
initialPageParam: undefined as string | undefined,
getNextPageParam: (lastPage) => lastPage.nextCursor,

Copilot AI Apr 2, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
getNextPageParam: (lastPage) => lastPage.nextCursor,
getNextPageParam: (lastPage) => lastPage.nextCursor,
enabled: !!manifest,

Copilot uses AI. Check for mistakes.
@fzihak

fzihak commented Apr 2, 2026

Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@pkg-pr-new

pkg-pr-new Bot commented Apr 2, 2026

Copy link
Copy Markdown

Open in StackBlitz

@emdash-cms/admin

npm i https://pkg.pr.new/@emdash-cms/admin@135

@emdash-cms/auth

npm i https://pkg.pr.new/@emdash-cms/auth@135

@emdash-cms/blocks

npm i https://pkg.pr.new/@emdash-cms/blocks@135

@emdash-cms/cloudflare

npm i https://pkg.pr.new/@emdash-cms/cloudflare@135

emdash

npm i https://pkg.pr.new/emdash@135

create-emdash

npm i https://pkg.pr.new/create-emdash@135

@emdash-cms/gutenberg-to-portable-text

npm i https://pkg.pr.new/@emdash-cms/gutenberg-to-portable-text@135

@emdash-cms/x402

npm i https://pkg.pr.new/@emdash-cms/x402@135

@emdash-cms/plugin-ai-moderation

npm i https://pkg.pr.new/@emdash-cms/plugin-ai-moderation@135

@emdash-cms/plugin-atproto

npm i https://pkg.pr.new/@emdash-cms/plugin-atproto@135

@emdash-cms/plugin-audit-log

npm i https://pkg.pr.new/@emdash-cms/plugin-audit-log@135

@emdash-cms/plugin-color

npm i https://pkg.pr.new/@emdash-cms/plugin-color@135

@emdash-cms/plugin-embeds

npm i https://pkg.pr.new/@emdash-cms/plugin-embeds@135

@emdash-cms/plugin-forms

npm i https://pkg.pr.new/@emdash-cms/plugin-forms@135

@emdash-cms/plugin-webhook-notifier

npm i https://pkg.pr.new/@emdash-cms/plugin-webhook-notifier@135

commit: 7a534ea

@ascorbic

ascorbic commented Apr 2, 2026

Copy link
Copy Markdown
Member

recheck

github-actions Bot added a commit that referenced this pull request Apr 2, 2026
@ascorbic
ascorbic merged commit 018be7f into emdash-cms:main Apr 4, 2026
19 of 21 checks passed
@ascorbic

ascorbic commented Apr 4, 2026

Copy link
Copy Markdown
Member

Thank you!

This was referenced Apr 4, 2026
r2sake added a commit to r2sake/emdash that referenced this pull request May 12, 2026
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.
ascorbic pushed a commit that referenced this pull request May 12, 2026
…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.
@emdashbot emdashbot Bot mentioned this pull request May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(admin): content list only loads 50 items, no infinite scroll for large datasets

3 participants