mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 17:35:10 +03:00
Live mode polled every 10 seconds for as long as the page stayed open, including in hidden tabs and tabs left unattended for hours. Move the polling loop into a useLivePolling hook that: - stops polling while the tab is hidden and polls immediately when it is visible again - pauses live mode after 15 minutes of visible time with no pointer, key, wheel, or scroll activity, with a notice to resume it - backs off from 10s to 20s, 40s, then 60s while polls find no new rows, resetting on new rows, activity, or the tab becoming visible Track clicks on the notice's "Resume live mode" button (unified_logs_live_mode_resume_button_clicked). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
62 lines
1.7 KiB
TypeScript
62 lines
1.7 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
|
|
import {
|
|
getLivePollDelay,
|
|
isEmptyLivePoll,
|
|
LIVE_POLL_BASE_INTERVAL_MS,
|
|
LIVE_POLL_MAX_INTERVAL_MS,
|
|
} from './LiveButton.utils'
|
|
|
|
describe('getLivePollDelay', () => {
|
|
it('polls at the base interval when the last poll found rows', () => {
|
|
expect(getLivePollDelay(0)).toBe(LIVE_POLL_BASE_INTERVAL_MS)
|
|
})
|
|
|
|
it('doubles the delay after each empty poll', () => {
|
|
expect(getLivePollDelay(1)).toBe(20_000)
|
|
expect(getLivePollDelay(2)).toBe(40_000)
|
|
})
|
|
|
|
it('caps the delay at the maximum interval', () => {
|
|
expect(getLivePollDelay(3)).toBe(LIVE_POLL_MAX_INTERVAL_MS)
|
|
expect(getLivePollDelay(50)).toBe(LIVE_POLL_MAX_INTERVAL_MS)
|
|
})
|
|
|
|
it('falls back to the base interval for negative or invalid counts', () => {
|
|
for (const count of [-1, NaN, Infinity]) {
|
|
expect(getLivePollDelay(count)).toBe(LIVE_POLL_BASE_INTERVAL_MS)
|
|
}
|
|
})
|
|
|
|
it('rounds fractional counts down', () => {
|
|
expect(getLivePollDelay(1.9)).toBe(20_000)
|
|
})
|
|
})
|
|
|
|
describe('isEmptyLivePoll', () => {
|
|
const pollResult = (pages: unknown) => ({ data: { pages } })
|
|
|
|
it('is true when the newest page has no rows', () => {
|
|
expect(isEmptyLivePoll(pollResult([{ data: [] }, { data: [{ id: 'a' }] }]))).toBe(true)
|
|
})
|
|
|
|
it('is false when the newest page has rows', () => {
|
|
expect(isEmptyLivePoll(pollResult([{ data: [{ id: 'b' }] }, { data: [] }]))).toBe(false)
|
|
})
|
|
|
|
it('is false for missing or malformed results', () => {
|
|
for (const result of [
|
|
undefined,
|
|
null,
|
|
{},
|
|
{ data: null },
|
|
pollResult(undefined),
|
|
pollResult([]),
|
|
pollResult([null]),
|
|
pollResult([{ data: 'rows' }]),
|
|
]) {
|
|
expect(isEmptyLivePoll(result)).toBe(false)
|
|
}
|
|
})
|
|
})
|