@@ -22,7 +22,13 @@ const MAX_RESULTS = 250
2222 * ```
2323 */
2424export function useUserPackages ( username : MaybeRefOrGetter < string > ) {
25+ const route = useRoute ( )
26+ const searchProviderParam = computed ( ( ) => {
27+ const p = normalizeSearchParam ( route . query . p )
28+ return p === 'npm' ? 'npm' : 'algolia'
29+ } )
2530 const { searchProvider } = useSearchProvider ( )
31+ const searchProviderValue = computed ( ( ) => searchProviderParam . value || searchProvider . value )
2632 // this is only used in npm path, but we need to extract it when the composable runs
2733 const { $npmRegistry } = useNuxtApp ( )
2834 const { searchByOwner } = useAlgoliaSearch ( )
@@ -32,7 +38,7 @@ export function useUserPackages(username: MaybeRefOrGetter<string>) {
3238
3339 /** Tracks which provider actually served the current data (may differ from
3440 * searchProvider when Algolia returns empty and we fall through to npm) */
35- const activeProvider = shallowRef < 'npm' | 'algolia' > ( searchProvider . value )
41+ const activeProvider = shallowRef < 'npm' | 'algolia' > ( searchProviderValue . value )
3642
3743 const cache = shallowRef < {
3844 username : string
@@ -43,22 +49,22 @@ export function useUserPackages(username: MaybeRefOrGetter<string>) {
4349 const isLoadingMore = shallowRef ( false )
4450
4551 const asyncData = useLazyAsyncData (
46- ( ) => `user-packages:${ searchProvider . value } :${ toValue ( username ) } ` ,
52+ ( ) => `user-packages:${ searchProviderValue . value } :${ toValue ( username ) } ` ,
4753 async ( { $npmRegistry } , { signal } ) => {
4854 const user = toValue ( username )
4955 if ( ! user ) {
5056 return emptySearchResponse ( )
5157 }
5258
53- const provider = searchProvider . value
59+ const provider = searchProviderValue . value
5460
5561 // --- Algolia: fetch all at once ---
5662 if ( provider === 'algolia' ) {
5763 try {
5864 const response = await searchByOwner ( user )
5965
6066 // Guard against stale response (user/provider changed during await)
61- if ( user !== toValue ( username ) || provider !== searchProvider . value ) {
67+ if ( user !== toValue ( username ) || provider !== searchProviderValue . value ) {
6268 return emptySearchResponse ( )
6369 }
6470
@@ -95,7 +101,7 @@ export function useUserPackages(username: MaybeRefOrGetter<string>) {
95101 )
96102
97103 // Guard against stale response (user/provider changed during await)
98- if ( user !== toValue ( username ) || provider !== searchProvider . value ) {
104+ if ( user !== toValue ( username ) || provider !== searchProviderValue . value ) {
99105 return emptySearchResponse ( )
100106 }
101107
@@ -193,11 +199,14 @@ export function useUserPackages(username: MaybeRefOrGetter<string>) {
193199
194200 // asyncdata will automatically rerun due to key, but we need to reset cache/page
195201 // when provider changes
196- watch ( searchProvider , newProvider => {
197- cache . value = null
198- currentPage . value = 1
199- activeProvider . value = newProvider
200- } )
202+ watch (
203+ ( ) => searchProviderValue . value ,
204+ newProvider => {
205+ cache . value = null
206+ currentPage . value = 1
207+ activeProvider . value = newProvider
208+ } ,
209+ )
201210
202211 // Computed data that uses cache (only if it belongs to the current username)
203212 const data = computed < NpmSearchResponse | null > ( ( ) => {
0 commit comments