Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
fa6c590
fix: org page fetching metadata at once
Adebesin-Cell Mar 5, 2026
824cba3
Merge branch 'main' into fix/org
Adebesin-Cell Mar 17, 2026
6e49401
feat: progressive loading for org packages
Adebesin-Cell Mar 17, 2026
3d53a70
Merge branch 'main' into fix/org
Adebesin-Cell Mar 18, 2026
8e5b116
Merge branch 'main' into fix/org
serhalp Apr 6, 2026
5686329
Merge branch 'main' into fix/org
ghostdevv Apr 9, 2026
89edc2b
refactor: use extended useVisibleItems for progressive org loading
Adebesin-Cell Apr 9, 2026
44cc1c2
[autofix.ci] apply automated fixes
autofix-ci[bot] Apr 13, 2026
611ecc6
Merge branch 'main' into fix/org
Adebesin-Cell Apr 13, 2026
7082536
fix: track remaining packages by name and support partial expand
Adebesin-Cell Apr 13, 2026
21ecd99
chore: remove accidentally committed config files
Adebesin-Cell Apr 13, 2026
c99df23
fix: show load-more when server has unfetched packages
Adebesin-Cell Apr 13, 2026
686ad04
refactor: progressive org loading with incremental batches
Adebesin-Cell Apr 13, 2026
f91feb3
fix: remove unnecessary quotes around org name in i18n message
Adebesin-Cell Apr 13, 2026
7e0f14c
Merge branch 'main' into fix/org
Adebesin-Cell Apr 13, 2026
68fe83b
Merge branch 'main' into fix/org
Adebesin-Cell Apr 14, 2026
91aaf01
fix: persist allPackageNames in Nuxt payload for client hydration
Adebesin-Cell Apr 14, 2026
2f85269
fix: batch Algolia getObjects requests for large orgs
Adebesin-Cell Apr 14, 2026
e22bd3c
fix: avoid spread into push for large batch results
Adebesin-Cell Apr 15, 2026
16dc489
Merge branch 'main' into fix/org
Adebesin-Cell Apr 15, 2026
b72db1f
Merge branch 'main' into fix/org
Adebesin-Cell Apr 18, 2026
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
1 change: 1 addition & 0 deletions .claude/skills/vite-plus
1 change: 1 addition & 0 deletions .trae/skills/vite-plus
76 changes: 76 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<!--VITE PLUS START-->
Comment thread
ghostdevv marked this conversation as resolved.
Outdated

# Using Vite+, the Unified Toolchain for the Web

This project is using Vite+, a unified toolchain built on top of Vite, Rolldown, Vitest, tsdown, Oxlint, Oxfmt, and Vite Task. Vite+ wraps runtime management, package management, and frontend tooling in a single global CLI called `vp`. Vite+ is distinct from Vite, but it invokes Vite through `vp dev` and `vp build`.

## Vite+ Workflow

`vp` is a global binary that handles the full development lifecycle. Run `vp help` to print a list of commands and `vp <command> --help` for information about a specific command.

### Start

- create - Create a new project from a template
- migrate - Migrate an existing project to Vite+
- config - Configure hooks and agent integration
- staged - Run linters on staged files
- install (`i`) - Install dependencies
- env - Manage Node.js versions

### Develop

- dev - Run the development server
- check - Run format, lint, and TypeScript type checks
- lint - Lint code
- fmt - Format code
- test - Run tests

### Execute

- run - Run monorepo tasks
- exec - Execute a command from local `node_modules/.bin`
- dlx - Execute a package binary without installing it as a dependency
- cache - Manage the task cache

### Build

- build - Build for production
- pack - Build libraries
- preview - Preview production build

### Manage Dependencies

Vite+ automatically detects and wraps the underlying package manager such as pnpm, npm, or Yarn through the `packageManager` field in `package.json` or package manager-specific lockfiles.

- add - Add packages to dependencies
- remove (`rm`, `un`, `uninstall`) - Remove packages from dependencies
- update (`up`) - Update packages to latest versions
- dedupe - Deduplicate dependencies
- outdated - Check for outdated packages
- list (`ls`) - List installed packages
- why (`explain`) - Show why a package is installed
- info (`view`, `show`) - View package information from the registry
- link (`ln`) / unlink - Manage local package links
- pm - Forward a command to the package manager

### Maintain

- upgrade - Update `vp` itself to the latest version

These commands map to their corresponding tools. For example, `vp dev --port 3000` runs Vite's dev server and works the same as Vite. `vp test` runs JavaScript tests through the bundled Vitest. The version of all tools can be checked using `vp --version`. This is useful when researching documentation, features, and bugs.

## Common Pitfalls

- **Using the package manager directly:** Do not use pnpm, npm, or Yarn directly. Vite+ can handle all package manager operations.
- **Always use Vite commands to run tools:** Don't attempt to run `vp vitest` or `vp oxlint`. They do not exist. Use `vp test` and `vp lint` instead.
- **Running scripts:** Vite+ commands take precedence over `package.json` scripts. If there is a `test` script defined in `scripts` that conflicts with the built-in `vp test` command, run it using `vp run test`.
- **Do not install Vitest, Oxlint, Oxfmt, or tsdown directly:** Vite+ wraps these tools. They must not be installed directly. You cannot upgrade these tools by installing their latest versions. Always use Vite+ commands.
- **Use Vite+ wrappers for one-off binaries:** Use `vp dlx` instead of package-manager-specific `dlx`/`npx` commands.
- **Import JavaScript modules from `vite-plus`:** Instead of importing from `vite` or `vitest`, all modules should be imported from the project's `vite-plus` dependency. For example, `import { defineConfig } from 'vite-plus';` or `import { expect, test, vi } from 'vite-plus/test';`. You must not install `vitest` to import test utilities.
- **Type-Aware Linting:** There is no need to install `oxlint-tsgolint`, `vp lint --type-aware` works out of the box.

## Review Checklist for Agents

- [ ] Run `vp install` after pulling remote changes and before getting started.
- [ ] Run `vp check` and `vp test` to validate changes.
<!--VITE PLUS END-->
37 changes: 28 additions & 9 deletions app/composables/npm/useAlgoliaSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,9 @@ export function useAlgoliaSearch() {
}
}

/** Fetch metadata for specific packages by exact name using Algolia's getObjects API. */
async function getPackagesByName(packageNames: string[]): Promise<NpmSearchResponse> {
if (packageNames.length === 0) {
return { isStale: false, objects: [], total: 0, time: new Date().toISOString() }
}
/** Fetch metadata for a single batch of packages (max 1000) by exact name. */
async function getPackagesByNameSlice(names: string[]): Promise<NpmSearchResult[]> {
if (names.length === 0) return []

const response = await $fetch<{ results: (AlgoliaHit | null)[] }>(
`https://${algolia.appId}-dsn.algolia.net/1/indexes/*/objects`,
Expand All @@ -229,7 +227,7 @@ export function useAlgoliaSearch() {
'x-algolia-application-id': algolia.appId,
},
body: {
requests: packageNames.map(name => ({
requests: names.map(name => ({
indexName,
objectID: name,
attributesToRetrieve: ATTRIBUTES_TO_RETRIEVE,
Expand All @@ -238,11 +236,31 @@ export function useAlgoliaSearch() {
},
)

const hits = response.results.filter((r): r is AlgoliaHit => r !== null && 'name' in r)
return response.results
.filter((r): r is AlgoliaHit => r !== null && 'name' in r)
.map(hitToSearchResult)
}

/** Fetch metadata for specific packages by exact name using Algolia's getObjects API. */
async function getPackagesByName(packageNames: string[]): Promise<NpmSearchResponse> {
if (packageNames.length === 0) {
return { isStale: false, objects: [], total: 0, time: new Date().toISOString() }
}

// Algolia getObjects has a limit of 1000 objects per request, so batch if needed
const BATCH_SIZE = 1000
const batches: string[][] = []
for (let i = 0; i < packageNames.length; i += BATCH_SIZE) {
batches.push(packageNames.slice(i, i + BATCH_SIZE))
}

const results = await Promise.all(batches.map(batch => getPackagesByNameSlice(batch)))
const allObjects = results.flat()

return {
isStale: false,
objects: hits.map(hitToSearchResult),
total: hits.length,
objects: allObjects,
total: allObjects.length,
time: new Date().toISOString(),
}
}
Expand Down Expand Up @@ -349,5 +367,6 @@ export function useAlgoliaSearch() {
searchWithSuggestions,
searchByOwner,
getPackagesByName,
getPackagesByNameSlice,
}
}
181 changes: 154 additions & 27 deletions app/composables/npm/useOrgPackages.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
import type { NpmSearchResponse, NpmSearchResult, PackageMetaResponse } from '#shared/types'
import { emptySearchResponse, metaToSearchResult } from './search-utils'
import { mapWithConcurrency } from '#shared/utils/async'

/** Number of packages to fetch metadata for in the initial load */
const INITIAL_BATCH_SIZE = 250

/** Max names per Algolia getObjects request */
const ALGOLIA_BATCH_SIZE = 1000

export interface OrgPackagesResponse extends NpmSearchResponse {
/** Total number of packages in the org (may exceed objects.length before loadAll) */
totalPackages: number
}

function emptyOrgResponse(): OrgPackagesResponse {
return {
...emptySearchResponse(),
totalPackages: 0,
}
}

/**
* Fetch all packages for an npm organization.
* Fetch packages for an npm organization with progressive loading.
*
* 1. Gets the authoritative package list from the npm registry (single request)
* 2. Fetches metadata from Algolia by exact name (single request)
* 3. Falls back to lightweight server-side package-meta lookups
* 2. Fetches metadata for the first batch immediately (fast SSR)
* 3. Remaining packages are loaded on-demand via `loadAll()`
*/
export function useOrgPackages(orgName: MaybeRefOrGetter<string>) {
const route = useRoute()
Expand All @@ -13,17 +35,24 @@ export function useOrgPackages(orgName: MaybeRefOrGetter<string>) {
if (p === 'npm' || searchProvider.value === 'npm') return 'npm'
return 'algolia'
})
const { getPackagesByName } = useAlgoliaSearch()
const { getPackagesByNameSlice } = useAlgoliaSearch()

// Tracks all package names so loadAll() knows what to fetch
const allNames = shallowRef<string[]>([])
const loadedObjects = shallowRef<NpmSearchResult[]>([])

// Promise lock — scoped inside the composable to avoid cross-instance sharing
let loadAllPromise: Promise<void> | null = null

const asyncData = useLazyAsyncData(
() => `org-packages:${searchProviderValue.value}:${toValue(orgName)}`,
async ({ ssrContext }, { signal }) => {
const org = toValue(orgName)
if (!org) {
return emptySearchResponse()
return emptyOrgResponse()
}

// Get the authoritative package list from the npm registry (single request)
// Get the authoritative package list from the npm registry
let packageNames: string[]
try {
const { packages } = await $fetch<{ packages: string[]; count: number }>(
Expand All @@ -32,7 +61,6 @@ export function useOrgPackages(orgName: MaybeRefOrGetter<string>) {
)
packageNames = packages
} catch (err) {
// Check if this is a 404 (org not found)
if (err && typeof err === 'object' && 'statusCode' in err && err.statusCode === 404) {
const error = createError({
statusCode: 404,
Expand All @@ -44,34 +72,120 @@ export function useOrgPackages(orgName: MaybeRefOrGetter<string>) {
}
throw error
}
// For other errors (network, etc.), return empty array to be safe
packageNames = []
}

if (packageNames.length === 0) {
return emptySearchResponse()
allNames.value = []
loadedObjects.value = []
return emptyOrgResponse()
}

// Fetch metadata + downloads from Algolia (single request via getObjects)
allNames.value = packageNames
const initialNames = packageNames.slice(0, INITIAL_BATCH_SIZE)

// Fetch metadata for first batch
let initialObjects: NpmSearchResult[] = []

if (searchProviderValue.value === 'algolia') {
try {
const response = await getPackagesByName(packageNames)
if (response.objects.length > 0) {
return response
}
initialObjects = await getPackagesByNameSlice(initialNames)
} catch {
// Fall through to npm registry path
// Fall through to npm fallback
}
}

// npm fallback: fetch lightweight metadata via server proxy
// Staleness guard
if (toValue(orgName) !== org) return emptyOrgResponse()

// npm fallback for initial batch
if (initialObjects.length === 0) {
const metaResults = await mapWithConcurrency(
initialNames,
async name => {
try {
return await $fetch<PackageMetaResponse>(
`/api/registry/package-meta/${encodePackageName(name)}`,
{ signal },
)
} catch {
return null
}
},
10,
)

if (toValue(orgName) !== org) return emptyOrgResponse()

initialObjects = metaResults
.filter((meta): meta is PackageMetaResponse => meta !== null)
.map(metaToSearchResult)
}

loadedObjects.value = initialObjects

return {
isStale: false,
objects: initialObjects,
total: initialObjects.length,
totalPackages: packageNames.length,
time: new Date().toISOString(),
} satisfies OrgPackagesResponse
},
{ default: emptyOrgResponse },
)

/** Load all remaining packages that weren't fetched in the initial batch. */
async function loadAll(): Promise<void> {
const names = allNames.value
if (names.length <= loadedObjects.value.length) return

// Reuse in-flight promise to prevent duplicate fetches
if (loadAllPromise) {
await loadAllPromise
return
}

loadAllPromise = _doLoadAll()
try {
await loadAllPromise
} finally {
loadAllPromise = null
}
}

async function _doLoadAll(): Promise<void> {
const names = allNames.value
const current = loadedObjects.value
if (names.length <= current.length) return

const org = toValue(orgName)
const remainingNames = names.slice(current.length)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

let newObjects: NpmSearchResult[] = []

if (searchProviderValue.value === 'algolia') {
const batches: string[][] = []
for (let i = 0; i < remainingNames.length; i += ALGOLIA_BATCH_SIZE) {
batches.push(remainingNames.slice(i, i + ALGOLIA_BATCH_SIZE))
}

const results = await Promise.allSettled(batches.map(batch => getPackagesByNameSlice(batch)))

if (toValue(orgName) !== org) return

for (const result of results) {
if (result.status === 'fulfilled') {
newObjects.push(...result.value)
}
}
} else {
const metaResults = await mapWithConcurrency(
packageNames,
remainingNames,
async name => {
try {
return await $fetch<PackageMetaResponse>(
`/api/registry/package-meta/${encodePackageName(name)}`,
{ signal },
)
} catch {
return null
Expand All @@ -80,19 +194,32 @@ export function useOrgPackages(orgName: MaybeRefOrGetter<string>) {
10,
)

const results: NpmSearchResult[] = metaResults
if (toValue(orgName) !== org) return

newObjects = metaResults
.filter((meta): meta is PackageMetaResponse => meta !== null)
.map(metaToSearchResult)
}

return {
if (newObjects.length > 0) {
const existingNames = new Set(current.map(o => o.package.name))
const deduped = newObjects.filter(o => !existingNames.has(o.package.name))
const all = [...current, ...deduped]
loadedObjects.value = all

// Update asyncData so the page sees the new objects
asyncData.data.value = {
isStale: false,
objects: results,
total: results.length,
objects: all,
total: all.length,
totalPackages: names.length,
time: new Date().toISOString(),
} satisfies NpmSearchResponse
},
{ default: emptySearchResponse },
)
}
}
}

return asyncData
return {
...asyncData,
loadAll,
}
}
Loading
Loading