From a9074efde899c3ef5c1f89bb2ddd7221d35864ea Mon Sep 17 00:00:00 2001 From: Copple <10214025+kiwicopple@users.noreply.github.com> Date: Tue, 3 Feb 2026 19:02:43 +0100 Subject: [PATCH] resolve all comments --- apps/www/pages/api/changelog.ts | 16 +++++++++++++--- apps/www/pages/changelog.tsx | 8 +++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/apps/www/pages/api/changelog.ts b/apps/www/pages/api/changelog.ts index a70adaed906..f22fb5b5fb1 100644 --- a/apps/www/pages/api/changelog.ts +++ b/apps/www/pages/api/changelog.ts @@ -2,12 +2,22 @@ import type { NextApiRequest, NextApiResponse } from 'next' import { fetchChangelogPage, recursiveDecodeURI } from '~/lib/changelog.server' export default async function handler(req: NextApiRequest, res: NextApiResponse) { + if (req.method !== 'GET') { + return res.status(405).json({ error: 'Method not allowed' }) + } + res.setHeader('Cache-Control', 'public, max-age=900, stale-while-revalidate=900') const encodedNext = (req.query.next ?? null) as string | null const next = recursiveDecodeURI(encodedNext) - const restPage = req.query.restPage ? Number(req.query.restPage) : 1 + const parsedRestPage = req.query.restPage ? Number(req.query.restPage) : 1 + const restPage = Number.isNaN(parsedRestPage) || parsedRestPage < 1 ? 1 : parsedRestPage - const data = await fetchChangelogPage({ next, restPage }) - res.status(200).json(data) + try { + const data = await fetchChangelogPage({ next, restPage }) + res.status(200).json(data) + } catch (error) { + console.error('Failed to fetch changelog:', error) + res.status(500).json({ error: 'Failed to fetch changelog' }) + } } diff --git a/apps/www/pages/changelog.tsx b/apps/www/pages/changelog.tsx index fe32652dc6f..95e8ea8d5c1 100644 --- a/apps/www/pages/changelog.tsx +++ b/apps/www/pages/changelog.tsx @@ -62,7 +62,9 @@ function ChangelogPage({ changelog, pageInfo, restPage }: ChangelogPageProps) { if (end) { params.set('next', end) } - params.set('restPage', String(currentRestPage + 1)) + // Cap restPage at 10 to avoid unnecessary API calls after all oldReleases are exhausted + const nextRestPage = Math.min(currentRestPage + 1, 10) + params.set('restPage', String(nextRestPage)) const response = await fetch(`/api/changelog?${params.toString()}`) if (!response.ok) { @@ -71,8 +73,8 @@ function ChangelogPage({ changelog, pageInfo, restPage }: ChangelogPageProps) { const data = await response.json() setEntries((prev) => prev.concat(data.changelog ?? [])) - setCurrentPageInfo(data.pageInfo ?? currentPageInfo) - setCurrentRestPage(data.restPage ?? currentRestPage + 1) + setCurrentPageInfo(data.pageInfo ?? { hasNextPage: false, endCursor: null }) + setCurrentRestPage(data.restPage ?? nextRestPage) } catch (error) { console.error(error) } finally {