1+ import { bridgeSearchSSRPayload } from './search-utils'
2+
13/** Default page size for incremental loading (npm registry path) */
24const PAGE_SIZE = 50 as const
35
@@ -19,13 +21,7 @@ const MAX_RESULTS = 250
1921 * ```
2022 */
2123export function useUserPackages ( username : MaybeRefOrGetter < string > ) {
22- const route = useRoute ( )
2324 const { searchProvider } = useSearchProvider ( )
24- const searchProviderValue = computed ( ( ) => {
25- const p = normalizeSearchParam ( route . query . p )
26- if ( p === 'npm' || searchProvider . value === 'npm' ) return 'npm'
27- return 'algolia'
28- } )
2925 // this is only used in npm path, but we need to extract it when the composable runs
3026 const { $npmRegistry } = useNuxtApp ( )
3127 const { searchByOwner } = useAlgoliaSearch ( )
@@ -35,7 +31,9 @@ export function useUserPackages(username: MaybeRefOrGetter<string>) {
3531
3632 /** Tracks which provider actually served the current data (may differ from
3733 * searchProvider when Algolia returns empty and we fall through to npm) */
38- const activeProvider = shallowRef < 'npm' | 'algolia' > ( searchProviderValue . value )
34+ const activeProvider = shallowRef < 'npm' | 'algolia' > ( searchProvider . value )
35+
36+ bridgeSearchSSRPayload ( 'user-packages' , username , searchProvider )
3937
4038 const cache = shallowRef < {
4139 username : string
@@ -46,22 +44,22 @@ export function useUserPackages(username: MaybeRefOrGetter<string>) {
4644 const isLoadingMore = shallowRef ( false )
4745
4846 const asyncData = useLazyAsyncData (
49- ( ) => `user-packages:${ searchProviderValue . value } :${ toValue ( username ) } ` ,
47+ ( ) => `user-packages:${ searchProvider . value } :${ toValue ( username ) } ` ,
5048 async ( _nuxtApp , { signal } ) => {
5149 const user = toValue ( username )
5250 if ( ! user ) {
5351 return emptySearchResponse ( )
5452 }
5553
56- const provider = searchProviderValue . value
54+ const provider = searchProvider . value
5755
5856 // --- Algolia: fetch all at once ---
5957 if ( provider === 'algolia' ) {
6058 try {
6159 const response = await searchByOwner ( user )
6260
6361 // Guard against stale response (user/provider changed during await)
64- if ( user !== toValue ( username ) || provider !== searchProviderValue . value ) {
62+ if ( user !== toValue ( username ) || provider !== searchProvider . value ) {
6563 return emptySearchResponse ( )
6664 }
6765
@@ -98,7 +96,7 @@ export function useUserPackages(username: MaybeRefOrGetter<string>) {
9896 )
9997
10098 // Guard against stale response (user/provider changed during await)
101- if ( user !== toValue ( username ) || provider !== searchProviderValue . value ) {
99+ if ( user !== toValue ( username ) || provider !== searchProvider . value ) {
102100 return emptySearchResponse ( )
103101 }
104102
@@ -197,7 +195,7 @@ export function useUserPackages(username: MaybeRefOrGetter<string>) {
197195 // asyncdata will automatically rerun due to key, but we need to reset cache/page
198196 // when provider changes
199197 watch (
200- ( ) => searchProviderValue . value ,
198+ ( ) => searchProvider . value ,
201199 newProvider => {
202200 cache . value = null
203201 currentPage . value = 1
@@ -231,8 +229,10 @@ export function useUserPackages(username: MaybeRefOrGetter<string>) {
231229 return fetched < available && fetched < MAX_RESULTS
232230 } )
233231
232+ const { data : _data , ...rest } = asyncData
233+
234234 return {
235- ...asyncData ,
235+ ...rest ,
236236 /** Reactive package results */
237237 data,
238238 /** Whether currently loading more results */
0 commit comments