Skip to content

fix: change default sorting to downloads-week-desc as in parseSortOption#2477

Open
t128n wants to merge 2 commits intonpmx-dev:mainfrom
t128n:fix/default-sorting-org-page
Open

fix: change default sorting to downloads-week-desc as in parseSortOption#2477
t128n wants to merge 2 commits intonpmx-dev:mainfrom
t128n:fix/default-sorting-org-page

Conversation

@t128n
Copy link
Copy Markdown
Contributor

@t128n t128n commented Apr 11, 2026

🔗 Linked issue

Resolves #2471

🧭 Context

Describe the bug

  • https://npmx.dev/org/arnaud-barre -> Sort dropdown is Downloads/wk
  • Change to Last published, no URL change
  • Change back to Downloads/wk, ?sort=downloads-week-desc is append to the URL

The makes it annoying in the following flow:

  • Change to last published, click the first one
  • Navigate back, you don't get back the list order

Changed default sorting on /org/ pages to match the default sorting method used in

export function parseSortOption(option: SortOption): {
key: SortKey
direction: SortDirection
} {
const match = option.match(/^(.+)-(asc|desc)$/)
if (match) {
const key = match[1]
const direction = match[2] as SortDirection
// Validate that the key is a known sort key
if (VALID_SORT_KEYS.has(key as SortKey)) {
return { key: key as SortKey, direction }
}
}
// Fallback to default sort option
return { key: 'downloads-week', direction: 'desc' }
}

📚 Description

/org/[org] pages used updated-desc as the default sorting method

initialSort: (normalizeSearchParam(route.query.sort) as SortOption) ?? 'updated-desc',

The ListToolbar component used on that page, relies on the fn parseSortOption, which uses downloads-week-desc as the default sorting method though, as defined in

export function parseSortOption(option: SortOption): {
key: SortKey
direction: SortDirection
} {
const match = option.match(/^(.+)-(asc|desc)$/)
if (match) {
const key = match[1]
const direction = match[2] as SortDirection
// Validate that the key is a known sort key
if (VALID_SORT_KEYS.has(key as SortKey)) {
return { key: key as SortKey, direction }
}
}
// Fallback to default sort option
return { key: 'downloads-week', direction: 'desc' }
}

So when /org/ used the default sorting method, it didn't save it in the URL query params. The /org/ page thought that updated-desc i was used, but ListToolbar thought that downloads-weeks-desc i was used. This caused the desync as outlined in the issue.

I adjusted the default on the /org/ page to align with the default set in shared/types/preferences.ts.

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 11, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
npmx.dev Ready Ready Preview, Comment Apr 12, 2026 6:37am
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
docs.npmx.dev Ignored Ignored Preview Apr 12, 2026 6:37am
npmx-lunaria Ignored Ignored Apr 12, 2026 6:37am

Request Review

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 11, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 63fcc503-9436-40aa-8c3b-7dae6484154d

📥 Commits

Reviewing files that changed from the base of the PR and between 943660b and f34bac3.

📒 Files selected for processing (1)
  • app/pages/org/[org].vue
✅ Files skipped from review due to trivial changes (1)
  • app/pages/org/[org].vue

📝 Walkthrough

Summary by CodeRabbit

  • Changes
    • Default sort order for organisations updated from "recently updated" to "most downloaded this week"
    • Organisation switching now resets the sort preference to the new default setting
    • URL query parameter handling adjusted to reflect the updated default sort

Walkthrough

The default sorting option on the organisation page has been changed from 'updated-desc' to 'downloads-week-desc'. The URL synchronisation logic has been updated to omit the sort query parameter when it matches the new default value, rather than the previous default.

Changes

Cohort / File(s) Summary
Org page sort logic
app/pages/org/[org].vue
Default initialSort fallback changed from 'updated-desc' to 'downloads-week-desc'; debounced URL sync now omits sort when it equals 'downloads-week-desc'; org-change reset logic calls setSort('downloads-week-desc') instead of 'updated-desc'.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: updating the default sorting from 'updated-desc' to 'downloads-week-desc' to align with the parseSortOption function.
Description check ✅ Passed The description clearly explains the bug, root cause, and solution with relevant code references and context about the desynchronisation issue.
Linked Issues check ✅ Passed The PR directly resolves issue #2471 by aligning the /org/ page default sorting with the shared preference default (downloads-week-desc), fixing the sort state desynchronisation.
Out of Scope Changes check ✅ Passed All changes are scoped to the sorting default alignment on the /org/[org].vue page, directly addressing the linked issue with no extraneous modifications.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
app/pages/org/[org].vue (1)

84-90: ⚠️ Potential issue | 🟠 Major

Default sort is still inconsistent on org-switch flow (Line 115).

Line 89 now treats 'downloads-week-desc' as default for URL sync, but Line 115 still resets to 'updated-desc'. On client-side org navigation, that can reintroduce mismatch and persist sort=updated-desc unexpectedly.

Suggested fix
+const ORG_DEFAULT_SORT: SortOption = 'downloads-week-desc'
@@
-  initialSort: parseSortOption(normalizeSearchParam(route.query.sort)),
+  initialSort: parseSortOption(normalizeSearchParam(route.query.sort)) ?? ORG_DEFAULT_SORT,
@@
-      sort: updates.sort && updates.sort !== 'downloads-week-desc' ? updates.sort : undefined,
+      sort: updates.sort && updates.sort !== ORG_DEFAULT_SORT ? updates.sort : undefined,
@@
-  setSort('updated-desc')
+  setSort(ORG_DEFAULT_SORT)

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0f107d08-ee6f-4ae7-99d4-b0343f9ad45b

📥 Commits

Reviewing files that changed from the base of the PR and between 0164064 and 943660b.

📒 Files selected for processing (1)
  • app/pages/org/[org].vue

Comment on lines 58 to 61
} = useStructuredFilters({
packages,
initialSort: (normalizeSearchParam(route.query.sort) as SortOption) ?? 'updated-desc',
initialSort: (normalizeSearchParam(route.query.sort) as SortOption) ?? 'downloads-week-desc',
})
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.

⚠️ Potential issue | 🟠 Major

Use parseSortOption (not a direct cast) for query-derived sort.

(normalizeSearchParam(route.query.sort) as SortOption) trusts arbitrary query input. An invalid ?sort= value can enter state and bypass the normal defaulting/parsing behaviour described in the PR objective.

Suggested fix
-import type { FilterChip, SortOption } from '#shared/types/preferences'
+import { parseSortOption, type FilterChip, type SortOption } from '#shared/types/preferences'
@@
-  initialSort: (normalizeSearchParam(route.query.sort) as SortOption) ?? 'downloads-week-desc',
+  initialSort: parseSortOption(normalizeSearchParam(route.query.sort)),

As per coding guidelines: "Ensure you write strictly type-safe code."

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
} = useStructuredFilters({
packages,
initialSort: (normalizeSearchParam(route.query.sort) as SortOption) ?? 'updated-desc',
initialSort: (normalizeSearchParam(route.query.sort) as SortOption) ?? 'downloads-week-desc',
})
} = useStructuredFilters({
packages,
initialSort: parseSortOption(normalizeSearchParam(route.query.sort)),
})

Copy link
Copy Markdown
Contributor

@ghostdevv ghostdevv left a comment

Choose a reason for hiding this comment

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

could you take a look at code rabbit's comment?

@t128n
Copy link
Copy Markdown
Contributor Author

t128n commented Apr 12, 2026

could you take a look at code rabbit's comment?

Totally missed that 2nd comment - just added another commit that fixes it

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.

Default sorting on org page doesn't match query params

2 participants