mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
## Problem The deliveries table polled the API every 5 seconds, for as long as the page was open. Studio tables are not polled by default, and polling is only needed here because delivery results arrive asynchronously. Stacked on #52314. Linear: [FE-3750](https://linear.app/supabase/issue/FE-3750/add-pagination-to-platform-webhooks-deliveries-table) ## Solution - Deliveries are no longer polled by default. - A **Live** button turns polling on (every 5 seconds), and a **Refresh** button reloads once. - Polling also turns on by itself while a delivery is pending, and after a test event or retry is sent until its delivery appears (30 seconds at most). The action never looks like it did nothing. - Hovering a failed delivery explains that failed deliveries are usually retried automatically. The API returns no retry state yet, so a scheduled retry only shows up once its attempt starts. ## Review instructions 1. Enable the Platform Webhooks feature preview, open an endpoint with deliveries, and filter DevTools > Network by `deliveries`. No request repeats on its own. 2. Click Refresh. One request is sent. 3. Click Live. A request is sent every 5 seconds and the dot pulses. Click Live again and the requests stop. 4. Send a test event. Requests repeat for a few seconds until the new row appears, then stop. 5. Set the endpoint URL to `https://httpbin.org/delay/10` and send a test event. While the new row shows `pending`, requests repeat. Once it shows `success`, they stop. 6. Hover a `failure` badge. The retry tooltip shows.
27 lines
949 B
TypeScript
27 lines
949 B
TypeScript
import { useEffect, useRef, useState } from 'react'
|
|
|
|
import { AWAITING_DELIVERY_TIMEOUT_MS } from './PlatformWebhooks.constants'
|
|
|
|
/**
|
|
* A test event or retry is queued, and its delivery lands in the table a moment later. While we
|
|
* wait for it the table polls, so the action does not look like it did nothing. The API does not
|
|
* tell us which delivery belongs to the action, so we wait for a fixed time.
|
|
*/
|
|
export const useAwaitingDelivery = () => {
|
|
const [isAwaitingDelivery, setIsAwaitingDelivery] = useState(false)
|
|
const timeoutRef = useRef<ReturnType<typeof setTimeout>>(undefined)
|
|
|
|
const startAwaitingDelivery = () => {
|
|
clearTimeout(timeoutRef.current)
|
|
setIsAwaitingDelivery(true)
|
|
timeoutRef.current = setTimeout(
|
|
() => setIsAwaitingDelivery(false),
|
|
AWAITING_DELIVERY_TIMEOUT_MS
|
|
)
|
|
}
|
|
|
|
useEffect(() => () => clearTimeout(timeoutRef.current), [])
|
|
|
|
return { isAwaitingDelivery, startAwaitingDelivery }
|
|
}
|