Skip to content

Commit 0925d70

Browse files
authored
[Render Preview] Switch Agent Store to SSG (#310)
1 parent b99cc00 commit 0925d70

File tree

5 files changed

+266
-207
lines changed

5 files changed

+266
-207
lines changed

bun.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/src/app/api/agents/route.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { unstable_cache } from 'next/cache'
66

77
import { logger } from '@/util/logger'
88

9-
// Cache for 60 seconds with stale-while-revalidate
10-
export const revalidate = 60
9+
// Enable static generation for API route
10+
export const revalidate = 600 // Cache for 10 minutes
1111

1212
// Cached function for expensive agent aggregations
1313
const getCachedAgents = unstable_cache(
@@ -251,7 +251,7 @@ const getCachedAgents = unstable_cache(
251251
},
252252
['agents-data'],
253253
{
254-
revalidate: 60,
254+
revalidate: 60 * 10, // Cache for 10 minutes
255255
tags: ['agents'],
256256
}
257257
)
@@ -265,9 +265,13 @@ export async function GET() {
265265
// Add cache headers for CDN and browser caching
266266
response.headers.set(
267267
'Cache-Control',
268-
'public, max-age=60, s-maxage=60, stale-while-revalidate=300'
268+
'public, max-age=600, s-maxage=600, stale-while-revalidate=600'
269269
)
270270

271+
// Add additional headers for better CDN caching
272+
response.headers.set('Vary', 'Accept-Encoding')
273+
response.headers.set('X-Content-Type-Options', 'nosniff')
274+
271275
return response
272276
} catch (error) {
273277
logger.error({ error }, 'Error fetching agents')

web/src/app/store/page.tsx

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { Suspense } from 'react'
22
import { Metadata } from 'next'
3-
import { getServerSession } from 'next-auth/next'
4-
import { authOptions } from '@/app/api/auth/[...nextauth]/auth-options'
53
import { unstable_cache } from 'next/cache'
64
import AgentStoreClient from './store-client'
75

@@ -84,29 +82,27 @@ export const metadata: Metadata = {
8482
},
8583
}
8684

87-
// Enable static generation with revalidation
88-
export const revalidate = 60
85+
// Enable static site generation with ISR
86+
export const revalidate = 60 * 10 // Revalidate every hour
8987

9088
interface StorePageProps {
9189
searchParams: { [key: string]: string | string[] | undefined }
9290
}
9391

9492
export default async function StorePage({ searchParams }: StorePageProps) {
95-
// Get session for conditional rendering
96-
const session = await getServerSession(authOptions)
97-
98-
// Fetch agents data at build time / on revalidation
93+
// Fetch agents data at build time
9994
const agentsData = await getCachedAgentsData()
10095

101-
// For now, pass empty array for publishers - client will handle this
96+
// For static generation, we don't pass session data
97+
// The client will handle authentication state
10298
const userPublishers: PublisherProfileResponse[] = []
10399

104100
return (
105101
<Suspense fallback={<StorePageSkeleton />}>
106102
<AgentStoreClient
107103
initialAgents={agentsData}
108104
initialPublishers={userPublishers}
109-
session={session}
105+
session={null} // Client will handle session
110106
searchParams={searchParams}
111107
/>
112108
</Suspense>

0 commit comments

Comments
 (0)