fix(pagespeed): poll for results after async check trigger

Backend now returns 202 immediately. Frontend polls every 5s for up
to 2 minutes until new results appear, then shows success toast.
This commit is contained in:
Usman Baig
2026-03-22 18:35:17 +01:00
parent d1af25266b
commit 2fd9bf82f1
2 changed files with 41 additions and 18 deletions

View File

@@ -75,17 +75,8 @@ export async function getPageSpeedCheck(siteId: string, checkId: string): Promis
return apiRequest<PageSpeedCheck>(`/sites/${siteId}/pagespeed/checks/${checkId}`)
}
export async function triggerPageSpeedCheck(siteId: string): Promise<PageSpeedCheck[]> {
// * PSI checks take 10-30s per strategy (mobile + desktop sequential = up to 60s)
const controller = new AbortController()
const timeoutId = setTimeout(() => controller.abort(), 120_000)
try {
const res = await apiRequest<{ checks: PageSpeedCheck[] }>(`/sites/${siteId}/pagespeed/check`, {
method: 'POST',
signal: controller.signal,
})
return res?.checks ?? []
} finally {
clearTimeout(timeoutId)
}
// * Triggers an async PageSpeed check. Returns immediately (202).
// * Caller should poll getPageSpeedLatest() for results.
export async function triggerPageSpeedCheck(siteId: string): Promise<void> {
await apiRequest(`/sites/${siteId}/pagespeed/check`, { method: 'POST' })
}