Skip to content

Commit bd25937

Browse files
committed
agent store: force static rendering
1 parent 0925d70 commit bd25937

File tree

4 files changed

+40
-50
lines changed

4 files changed

+40
-50
lines changed

web/next.config.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ const nextConfig = {
1515
// Disable ESLint during builds
1616
ignoreDuringBuilds: true,
1717
},
18+
19+
// Enable experimental features for better SSG performance
20+
experimental: {
21+
optimizePackageImports: ['@/components/ui'],
22+
},
1823
webpack: (config) => {
1924
config.resolve.fallback = { fs: false, net: false, tls: false }
2025
// Tell Next.js to leave pino and thread-stream unbundled

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { logger } from '@/util/logger'
88

99
// Enable static generation for API route
1010
export const revalidate = 600 // Cache for 10 minutes
11+
export const dynamic = 'force-static' // Force static generation
12+
export const fetchCache = 'force-cache' // Use cached data when possible
1113

1214
// Cached function for expensive agent aggregations
1315
const getCachedAgents = unstable_cache(
@@ -251,7 +253,7 @@ const getCachedAgents = unstable_cache(
251253
},
252254
['agents-data'],
253255
{
254-
revalidate: 60 * 10, // Cache for 10 minutes
256+
revalidate,
255257
tags: ['agents'],
256258
}
257259
)

web/src/app/store/page.tsx

Lines changed: 21 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { Suspense } from 'react'
21
import { Metadata } from 'next'
32
import { unstable_cache } from 'next/cache'
43
import AgentStoreClient from './store-client'
@@ -83,7 +82,21 @@ export const metadata: Metadata = {
8382
}
8483

8584
// Enable static site generation with ISR
86-
export const revalidate = 60 * 10 // Revalidate every hour
85+
export const revalidate = 60 * 10 // Revalidate every 10 minutes
86+
87+
// Generate static params for common search/sort combinations
88+
export async function generateStaticParams() {
89+
// Generate static versions for the most common combinations
90+
const commonParams = [
91+
{}, // Default: no search, default sort
92+
{ sort: 'usage' },
93+
{ sort: 'unique_users' },
94+
{ sort: 'newest' },
95+
{ sort: 'name' },
96+
]
97+
98+
return commonParams
99+
}
87100

88101
interface StorePageProps {
89102
searchParams: { [key: string]: string | string[] | undefined }
@@ -98,44 +111,11 @@ export default async function StorePage({ searchParams }: StorePageProps) {
98111
const userPublishers: PublisherProfileResponse[] = []
99112

100113
return (
101-
<Suspense fallback={<StorePageSkeleton />}>
102-
<AgentStoreClient
103-
initialAgents={agentsData}
104-
initialPublishers={userPublishers}
105-
session={null} // Client will handle session
106-
searchParams={searchParams}
107-
/>
108-
</Suspense>
109-
)
110-
}
111-
112-
// Loading skeleton component
113-
function StorePageSkeleton() {
114-
return (
115-
<div className="container mx-auto py-8 px-4">
116-
<div className="max-w-7xl mx-auto">
117-
{/* Header Skeleton */}
118-
<div className="mb-12">
119-
<div className="h-10 bg-muted rounded-lg w-64 mb-4" />
120-
<div className="h-6 bg-muted rounded w-96" />
121-
</div>
122-
123-
{/* Search and Filter Skeleton */}
124-
<div className="mb-8">
125-
<div className="flex gap-4">
126-
<div className="h-10 bg-muted rounded flex-1 max-w-sm" />
127-
<div className="h-10 bg-muted rounded w-32" />
128-
<div className="h-10 bg-muted rounded w-32" />
129-
</div>
130-
</div>
131-
132-
{/* Grid Skeleton */}
133-
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
134-
{Array.from({ length: 6 }).map((_, i) => (
135-
<div key={i} className="h-64 bg-muted rounded-lg animate-pulse" />
136-
))}
137-
</div>
138-
</div>
139-
</div>
114+
<AgentStoreClient
115+
initialAgents={agentsData}
116+
initialPublishers={userPublishers}
117+
session={null} // Client will handle session
118+
searchParams={searchParams}
119+
/>
140120
)
141121
}

web/src/app/store/store-client.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,13 @@ export default function AgentStoreClient({
126126
session: initialSession,
127127
searchParams,
128128
}: AgentStoreClientProps) {
129-
// Use client-side session for authentication state
130-
const { data: clientSession } = useSession()
129+
// Use client-side session for authentication state, but don't block rendering
130+
const { data: clientSession, status: sessionStatus } = useSession()
131131
const session = clientSession || initialSession
132132

133+
// Don't block rendering on session loading
134+
const isSessionReady = sessionStatus !== 'loading'
135+
133136
// Global state for persistence across navigation
134137
const {
135138
displayedCount,
@@ -220,7 +223,7 @@ export default function AgentStoreClient({
220223
})
221224
}, [editorsChoice, searchQuery])
222225

223-
const ITEMS_PER_PAGE = 12
226+
const ITEMS_PER_PAGE = 24
224227

225228
// Derive displayed agents from count.
226229
const displayedAgents = useMemo(() => {
@@ -308,7 +311,7 @@ export default function AgentStoreClient({
308311
}
309312
}, [loadMoreItems])
310313

311-
// Fetch user's publishers if signed in
314+
// Fetch user's publishers if signed in, but don't block rendering
312315
const { data: publishers } = useQuery<PublisherProfileResponse[]>({
313316
queryKey: ['user-publishers'],
314317
queryFn: async () => {
@@ -318,13 +321,13 @@ export default function AgentStoreClient({
318321
}
319322
return response.json()
320323
},
321-
enabled: !!session?.user?.id,
324+
enabled: !!session?.user?.id && isSessionReady,
322325
})
323326

324-
// Publisher button logic
325327
const renderPublisherButton = () => {
326-
if (!session) {
327-
return null // Don't show anything if signed out
328+
// Only render when session is ready to prevent hydration mismatches
329+
if (!isSessionReady || !session) {
330+
return null
328331
}
329332

330333
if (!publishers || publishers.length === 0) {

0 commit comments

Comments
 (0)