Skip to content

Commit 840270a

Browse files
authored
fix: prerender issues (#2223)
1 parent d7a97d4 commit 840270a

File tree

5 files changed

+30
-7
lines changed

5 files changed

+30
-7
lines changed

app/components/header/HeaderToggle.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script setup lang="ts">
22
import { motion } from 'motion-v'
33
import type { VariantType } from 'motion-v'
4+
import { useLocale } from '@nuxt/ui/composables/useLocale'
45
56
const props = defineProps<{
67
open: boolean

app/pages/docs/[...slug].vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ watch(page, (page) => {
7979
}, { immediate: true })
8080
8181
// Get the -2 item of the breadcrumb
82-
const currentSectionTitle = computed(() => headerLinks.value[0].children.find(link => path.value.includes(link.to))?.label || findPageBreadcrumb(navigation.value, path.value).slice(-1)[0].title)
82+
const currentSectionTitle = computed(() =>
83+
headerLinks.value[0]?.children?.find(link => path.value.includes(link.to))?.label
84+
|| findPageBreadcrumb(navigation.value, path.value).slice(-1)[0]?.title
85+
|| '')
8386
8487
const breadcrumb = computed(() => {
8588
const links = mapContentNavigation(findPageBreadcrumb(navigation.value, path.value)).map(link => ({

server/api/sponsors/index.get.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
import type { Sponsor, SponsorType } from '#shared/types'
22

33
export default cachedEventHandler(async (event) => {
4-
const sponsors = await Promise.all([
5-
fetchGithubSponsors(event),
6-
fetchOpenCollectiveSponsors(event)
7-
])
4+
let sponsors: [Sponsor[], Sponsor[]]
5+
try {
6+
sponsors = await Promise.all([
7+
fetchGithubSponsors(event),
8+
fetchOpenCollectiveSponsors(event)
9+
])
10+
} catch (e) {
11+
console.warn('[sponsors] Failed to load sponsor data, returning empty tiers:', e)
12+
sponsors = [[], []]
13+
}
814

915
const sponsorsByTier: Record<SponsorType, Array<Sponsor>> = {
1016
diamond: [],

server/utils/npm.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ async function npmFetch<T>(url: string): Promise<T | null> {
4444
}
4545
}
4646

47-
console.error(`Failed to fetch ${url} after ${maxRetries} retries: ${lastError}`)
47+
const wasRateLimited = lastError?.status === 429 || lastError?.statusCode === 429
48+
console[wasRateLimited ? 'warn' : 'error'](`Failed to fetch ${url} after ${maxRetries} retries: ${lastError}`)
4849

4950
return null
5051
}
@@ -101,9 +102,11 @@ export const npm = {
101102
}
102103
}
103104

104-
// Fetch scoped packages individually (not supported in bulk queries)
105+
// Fetch scoped packages individually (not supported in bulk queries).
106+
// Small delay between calls to avoid npm registry 429s during full prerender/build.
105107
for (const pkg of scopedPackages) {
106108
result[pkg] = await this.fetchPackageStats(pkg, period)
109+
await new Promise(r => setTimeout(r, 75))
107110
}
108111

109112
return result

server/utils/sponsors.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ export interface OpenCollectiveSponsor {
3939
}
4040

4141
export async function fetchOpenCollectiveSponsors(event: H3Event): Promise<OpenCollectiveSponsor[]> {
42+
if (!useRuntimeConfig(event).openCollective.apiKey) {
43+
console.warn('[sponsors] Skipping Open Collective: NUXT_OPEN_COLLECTIVE_API_KEY is not set')
44+
return []
45+
}
46+
4247
const key = `sponsors:opencollective`
4348
const cached = await kv.get<OpenCollectiveSponsor[]>(key)
4449
if (cached) {
@@ -150,6 +155,11 @@ export async function fetchOpenCollectiveSponsors(event: H3Event): Promise<OpenC
150155
}
151156

152157
export const fetchGithubSponsors = async (event: H3Event): Promise<Sponsor[]> => {
158+
if (!useRuntimeConfig(event).github.token) {
159+
console.warn('[sponsors] Skipping GitHub sponsors: NUXT_GITHUB_TOKEN is not set')
160+
return []
161+
}
162+
153163
const response: Sponsor[] = []
154164
const first = 100
155165
let cursor: string | null = null

0 commit comments

Comments
 (0)