Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 54 additions & 38 deletions app/pages/search.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { isPlatformSpecificPackage } from '~/utils/platform-packages'
import { normalizeSearchParam } from '#shared/utils/url'

const route = useRoute()
const router = useRouter()

// Preferences (persisted to localStorage)
const {
Expand All @@ -21,13 +20,16 @@ const {
} = usePackageListPreferences()

// Debounced URL update for page (less aggressive to avoid too many URL changes)
//Use History API directly to update URL without triggering Router's scroll-to-top
const updateUrlPage = debounce((page: number) => {
router.replace({
query: {
...route.query,
page: page > 1 ? page : undefined,
},
})
const url = new URL(window.location.href)
if (page > 1) {
url.searchParams.set('page', page.toString())
} else {
url.searchParams.delete('page')
}
// This updates the address bar "silently"
window.history.replaceState(window.history.state, '', url)
}, 500)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Comment thread
coderabbitai[bot] marked this conversation as resolved.

const { model: searchQuery, provider: searchProvider } = useGlobalSearch()
Expand Down Expand Up @@ -269,14 +271,18 @@ async function loadMore() {
currentPage.value++
await fetchMore(requestedSize.value)
}
onBeforeUnmount(() => {
updateUrlPage.cancel()
})

// Update URL when page changes from scrolling
function handlePageChange(page: number) {
updateUrlPage(page)
}

// Reset page when query changes
watch(query, () => {
watch(query, (newQuery, oldQuery) => {
if (newQuery.trim() === (oldQuery || '').trim()) return
currentPage.value = 1
hasInteracted.value = true
})
Expand Down Expand Up @@ -390,20 +396,24 @@ const totalSelectableCount = computed(() => suggestionCount.value + resultCount.
* Get all focusable result elements in DOM order (suggestions first, then packages)
*/
function getFocusableElements(): HTMLElement[] {
const suggestions = Array.from(
document.querySelectorAll<HTMLElement>('[data-suggestion-index]'),
).sort((a, b) => {
const aIdx = Number.parseInt(a.dataset.suggestionIndex ?? '0', 10)
const bIdx = Number.parseInt(b.dataset.suggestionIndex ?? '0', 10)
return aIdx - bIdx
})
const packages = Array.from(document.querySelectorAll<HTMLElement>('[data-result-index]')).sort(
(a, b) => {
const isVisible = (el: HTMLElement) => el.getClientRects().length > 0

const suggestions = Array.from(document.querySelectorAll<HTMLElement>('[data-suggestion-index]'))
.filter(isVisible)
.sort((a, b) => {
const aIdx = Number.parseInt(a.dataset.suggestionIndex ?? '0', 10)
const bIdx = Number.parseInt(b.dataset.suggestionIndex ?? '0', 10)
return aIdx - bIdx
})

const packages = Array.from(document.querySelectorAll<HTMLElement>('[data-result-index]'))
.filter(isVisible)
.sort((a, b) => {
const aIdx = Number.parseInt(a.dataset.resultIndex ?? '0', 10)
const bIdx = Number.parseInt(b.dataset.resultIndex ?? '0', 10)
return aIdx - bIdx
},
)
})

return [...suggestions, ...packages]
}

Expand Down Expand Up @@ -536,7 +546,7 @@ defineOgImageComponent('Default', {
</script>

<template>
<main class="flex-1 py-8" :class="{ 'overflow-x-hidden': viewMode !== 'table' }">
<main class="flex-1 py-8 search-page" :class="{ 'overflow-x-hidden': viewMode !== 'table' }">
<div class="container-sm">
<div class="flex items-center justify-between gap-4 mb-4">
<h1 class="font-mono text-2xl sm:text-3xl font-medium">
Expand All @@ -545,13 +555,22 @@ defineOgImageComponent('Default', {
<SearchProviderToggle />
</div>

<section v-if="query">
<!-- Initial loading (only after user interaction, not during view transition) -->
<section v-if="query" class="results-layout">
<LoadingSpinner v-if="showSearching" :text="$t('search.searching')" />

<div v-else-if="visibleResults">
<!-- User/Org search suggestions -->
<div v-if="validatedSuggestions.length > 0" class="mb-6 space-y-3">
<div
v-show="
results ||
displayResults.length > 0 ||
isRateLimited ||
status === 'error' ||
status === 'success'
"
>
<div
v-if="validatedSuggestions.length > 0 && displayResults.length > 0"
class="mb-6 space-y-3"
>
<SearchSuggestionCard
v-for="(suggestion, idx) in validatedSuggestions"
:key="`${suggestion.type}-${suggestion.name}`"
Expand All @@ -565,9 +584,8 @@ defineOgImageComponent('Default', {
/>
</div>

<!-- Claim prompt - shown at top when valid name but no exact match -->
<div
v-if="showClaimPrompt && visibleResults.total > 0"
v-if="showClaimPrompt && visibleResults && displayResults.length > 0"
class="mb-6 p-4 bg-bg-subtle border border-border rounded-lg sm:flex hidden flex-row sm:items-center gap-3 sm:gap-4"
>
<div class="flex-1 min-w-0">
Expand All @@ -585,15 +603,13 @@ defineOgImageComponent('Default', {
</button>
</div>

<!-- Rate limited by npm - check FIRST before showing any results -->
<div v-if="isRateLimited" role="status" class="py-12">
<p class="text-fg-muted font-mono mb-6 text-center">
{{ $t('search.rate_limited') }}
</p>
</div>

<!-- Enhanced toolbar -->
<div v-else-if="visibleResults.total > 0" class="mb-6">
<div v-else-if="visibleResults && displayResults.length > 0" class="mb-6">
<PackageListToolbar
:filters="filters"
v-model:sort-option="sortOption"
Expand All @@ -618,7 +634,6 @@ defineOgImageComponent('Default', {
@update:updated-within="setUpdatedWithin"
@toggle-keyword="toggleKeyword"
/>
<!-- Show count status (infinite scroll mode only) -->
<p
v-if="viewMode === 'cards' && paginationMode === 'infinite'"
role="status"
Expand All @@ -642,7 +657,6 @@ defineOgImageComponent('Default', {
$t('search.updating')
}}</span>
</p>
<!-- Show "x of y" (paginated/table mode only) -->
<p
v-if="viewMode === 'table' || paginationMode === 'paginated'"
role="status"
Expand All @@ -664,13 +678,11 @@ defineOgImageComponent('Default', {
</p>
</div>

<!-- No results found -->
<div v-else-if="status === 'success' || status === 'error'" role="status" class="py-12">
<p class="text-fg-muted font-mono mb-6 text-center">
{{ $t('search.no_results', { query }) }}
</p>

<!-- User/Org suggestions when no packages found -->
<div v-if="validatedSuggestions.length > 0" class="max-w-md mx-auto mb-6 space-y-3">
<SearchSuggestionCard
v-for="(suggestion, idx) in validatedSuggestions"
Expand All @@ -685,7 +697,6 @@ defineOgImageComponent('Default', {
/>
</div>

<!-- Offer to claim the package name if it's valid -->
<div v-if="showClaimPrompt" class="max-w-md mx-auto text-center hidden sm:block">
<div class="p-4 bg-bg-subtle border border-border rounded-lg">
<p class="text-sm text-fg-muted mb-3">{{ $t('search.want_to_claim') }}</p>
Expand All @@ -701,7 +712,7 @@ defineOgImageComponent('Default', {
</div>

<PackageList
v-if="displayResults.length > 0 && !isRateLimited"
v-show="displayResults.length > 0 && !isRateLimited"
Comment thread
coderabbitai[bot] marked this conversation as resolved.
:results="displayResults"
:search-query="query"
:filters="filters"
Expand All @@ -722,7 +733,6 @@ defineOgImageComponent('Default', {
@click-keyword="toggleKeyword"
/>

<!-- Pagination controls -->
<PaginationControls
v-if="displayResults.length > 0 && !isRateLimited"
v-model:mode="paginationMode"
Expand All @@ -739,7 +749,6 @@ defineOgImageComponent('Default', {
</section>
</div>

<!-- Claim package modal -->
<PackageClaimPackageModal
ref="claimPackageModalRef"
:package-name="query"
Expand All @@ -748,3 +757,10 @@ defineOgImageComponent('Default', {
/>
</main>
</template>

<style scoped>
.results-layout {
min-height: 50vh;
overflow-anchor: none;
}
</style>
22 changes: 16 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
"private": true,
"type": "module",
"version": "0.0.0",
"author": {
"name": "Daniel Roe",
"email": "daniel@roe.dev",
"url": "https://roe.dev"
},
"author": "Daniel Roe <daniel@roe.dev> (https://roe.dev)",
"scripts": {
"build": "nuxt build",
"build:lunaria": "node ./lunaria/lunaria.ts",
Expand Down Expand Up @@ -167,5 +163,19 @@
"pnpm oxfmt"
]
},
"packageManager": "pnpm@10.30.1"
"packageManager": "pnpm@10.30.1",
"description": "> A fast, modern browser for the npm registry.",
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 | 🟡 Minor

Strip the Markdown blockquote prefix from description.

The value "> A fast, modern browser for the npm registry." contains a literal > (Markdown blockquote syntax). It will appear verbatim in registry UIs, IDE tooltips, and any tooling that reads this field.

🐛 Proposed fix
-  "description": "> A fast, modern browser for the npm registry.",
+  "description": "A fast, modern browser for the npm registry.",
📝 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
"description": "> A fast, modern browser for the npm registry.",
"description": "A fast, modern browser for the npm registry.",

"main": "index.js",
"directories": {
"doc": "docs",
"test": "test"
},
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 | 🟡 Minor

main and directories are not applicable to a private Nuxt application.

"main": "index.js" implies a Node.js library entry point; no such file exists in a Nuxt SSR project and the package is already marked "private": true. directories is a legacy npm artefact. Both fields are likely unintentional npm init output and should be removed.

🐛 Proposed fix
-  "main": "index.js",
-  "directories": {
-    "doc": "docs",
-    "test": "test"
-  },
📝 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
"main": "index.js",
"directories": {
"doc": "docs",
"test": "test"
},

"repository": {
"type": "git",
"url": "git+https://github.com/marlonwq/npmx.dev.git"
},
"bugs": {
"url": "https://github.com/marlonwq/npmx.dev/issues"
},
"homepage": "https://github.com/marlonwq/npmx.dev#readme"
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

These metadata additions are unrelated to the PR objective and appear to be npm init artefacts.

The PR is scoped to fixing a scroll-jump regression during pagination. All changes from line 167 onward (description, main, directories, repository, bugs, homepage) were not part of the stated fix and look like side-effects of running npm init on the fork. Please remove or split them into a separate, intentional PR.

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

Fork-scoped URLs must not be merged into the upstream repository.

repository.url, bugs.url, and homepage all point to marlonwq/npmx.dev — the contributor's personal fork — rather than the canonical upstream npmx-dev/npmx.dev. If merged, these would direct tooling, registry links, and issue trackers to the wrong repository.

🐛 Proposed fix
-  "repository": {
-    "type": "git",
-    "url": "git+https://github.com/marlonwq/npmx.dev.git"
-  },
-  "bugs": {
-    "url": "https://github.com/marlonwq/npmx.dev/issues"
-  },
-  "homepage": "https://github.com/marlonwq/npmx.dev#readme"
+  "repository": {
+    "type": "git",
+    "url": "git+https://github.com/npmx-dev/npmx.dev.git"
+  },
+  "bugs": {
+    "url": "https://github.com/npmx-dev/npmx.dev/issues"
+  },
+  "homepage": "https://github.com/npmx-dev/npmx.dev#readme"
📝 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
"repository": {
"type": "git",
"url": "git+https://github.com/marlonwq/npmx.dev.git"
},
"bugs": {
"url": "https://github.com/marlonwq/npmx.dev/issues"
},
"homepage": "https://github.com/marlonwq/npmx.dev#readme"
"repository": {
"type": "git",
"url": "git+https://github.com/npmx-dev/npmx.dev.git"
},
"bugs": {
"url": "https://github.com/npmx-dev/npmx.dev/issues"
},
"homepage": "https://github.com/npmx-dev/npmx.dev#readme"

}
Loading