Skip to content

fix: sort collection items before pagination in published site#118

Merged
liamwalder merged 2 commits intodevelopfrom
fix/published-collection-field-sort
Apr 1, 2026
Merged

fix: sort collection items before pagination in published site#118
liamwalder merged 2 commits intodevelopfrom
fix/published-collection-field-sort

Conversation

@lunenas
Copy link
Copy Markdown
Collaborator

@lunenas lunenas commented Mar 31, 2026

Summary

Fix field-based sorting (e.g. by date) on published collection pages. Items were
sorted incorrectly because the DB paginated by manual_order first, then
client-side sort only reordered that subset — giving the wrong items for the
requested sort order.

Changes

  • When field-based sorting is active, skip DB-level limit/offset so all items are fetched
  • Sort the full item set by the requested field, then apply limit/offset via slice()
  • Manual, random, and no-sort modes continue to use DB-level pagination unchanged

Test plan

  • Add a collection layer to a page, sort by a date field descending
  • Publish the site and verify items appear in correct chronological order
  • Test with pagination enabled — verify each page shows the correct sorted subset
  • Test with a limit (no pagination) — verify the N most recent items are shown
  • Verify manual sort order still works correctly
  • Verify random sort still works

Made with Cursor

When a collection layer uses field-based sorting (e.g. by date), the DB
was paginating by manual_order first, then client-side sort only
reordered that subset. This gave wrong results because the correct
items for the sorted view might not be in the DB-returned page.

Now fetch all items when field-based sorting is active, sort the full
set, then apply limit/offset via slice to get the correct page.

Made-with: Cursor
@liamwalder liamwalder merged commit bc6d34a into develop Apr 1, 2026
2 checks passed
@liamwalder liamwalder deleted the fix/published-collection-field-sort branch April 1, 2026 09:41
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.

2 participants