:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(web-analytics): disable health Refresh during cooldown (#68472)
posthog[bot]12c96f288101
diff --git a/frontend/src/scenes/web-analytics/health/HealthStatusTab.tsx b/frontend/src/scenes/web-analytics/health/HealthStatusTab.tsxindex 953743023b90..e7edac51db6f 100644--- a/frontend/src/scenes/web-analytics/health/HealthStatusTab.tsx+++ b/frontend/src/scenes/web-analytics/health/HealthStatusTab.tsx@@ -8,7 +8,8 @@ import { HealthCheck } from './healthCheckTypes'import { webAnalyticsHealthLogic } from './webAnalyticsHealthLogic'export function HealthStatusTab(): JSX.Element {- const { overallHealthStatus, checksByCategory, healthIssuesLoading } = useValues(webAnalyticsHealthLogic)+ const { overallHealthStatus, checksByCategory, healthIssuesLoading, refreshDisabledReason } =+ useValues(webAnalyticsHealthLogic)const { refreshHealthChecks, trackSectionToggled } = useActions(webAnalyticsHealthLogic)return (@@ -20,6 +21,7 @@ export function HealthStatusTab(): JSX.Element {totalCount={overallHealthStatus.totalCount}onRefresh={refreshHealthChecks}loading={healthIssuesLoading}+ refreshDisabledReason={refreshDisabledReason}/><div className="space-y-3">@@ -55,6 +57,7 @@ interface OverallHealthBannerProps {totalCount: numberonRefresh: () => voidloading: boolean+ refreshDisabledReason: string | null}function OverallHealthBanner({@@ -64,6 +67,7 @@ function OverallHealthBanner({totalCount,onRefresh,loading,+ refreshDisabledReason,}: OverallHealthBannerProps): JSX.Element {if (status === 'loading') {return (@@ -91,6 +95,7 @@ function OverallHealthBanner({icon={<IconRefresh />}onClick={() => onRefresh()}loading={loading}+ disabledReason={loading ? undefined : refreshDisabledReason}>Refresh</LemonButton>diff --git a/frontend/src/scenes/web-analytics/health/webAnalyticsHealthLogic.ts b/frontend/src/scenes/web-analytics/health/webAnalyticsHealthLogic.tsindex 7d545cca51b7..aceec8a5b803 100644--- a/frontend/src/scenes/web-analytics/health/webAnalyticsHealthLogic.ts+++ b/frontend/src/scenes/web-analytics/health/webAnalyticsHealthLogic.ts@@ -3,6 +3,7 @@ import { loaders } from 'kea-loaders'import api, { ApiError } from 'lib/api'import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'+import { humanFriendlyDuration } from 'lib/utils/durations'import { eventUsageLogic } from 'lib/utils/eventUsageLogic'import type { HealthIssuesResponse } from 'scenes/health/healthSceneLogic'import {@@ -132,7 +133,9 @@ export interface webAnalyticsHealthLogicValues {healthIssues: HealthIssuesResponse | nullhealthIssuesLoading: booleannextRefreshAvailableAt: number | null+ now: numberoverallHealthStatus: OverallHealthStatus+ refreshDisabledReason: string | nullurgentFailedChecks: HealthCheck[]}@@ -216,6 +219,12 @@ export interface webAnalyticsHealthLogicActions {setNextRefreshAvailableAt: (timestamp: number | null) => {timestamp: number | null}+ setNow: (now: number) => {+ now: number+ }+ startCooldownCountdown: () => {+ value: true+ }trackActionClicked: (checkId: HealthCheckId,category: HealthCheckCategory,@@ -253,6 +262,7 @@ export interface webAnalyticsHealthLogicMeta {hasIssues: (overallHealthStatus: OverallHealthStatus) => booleanurgentFailedChecks: (allChecks: HealthCheck[]) => HealthCheck[]hasUrgentIssues: (urgentFailedChecks: HealthCheck[]) => boolean+ refreshDisabledReason: (nextRefreshAvailableAt: number | null, now: number) => string | null}}@@ -296,6 +306,8 @@ export const webAnalyticsHealthLogic = kea<webAnalyticsHealthLogicType>([isUrgent,}),setNextRefreshAvailableAt: (timestamp: number | null) => ({ timestamp }),+ setNow: (now: number) => ({ now }),+ startCooldownCountdown: true,}),reducers({@@ -306,6 +318,12 @@ export const webAnalyticsHealthLogic = kea<webAnalyticsHealthLogicType>([setNextRefreshAvailableAt: (_, { timestamp }) => timestamp,},],+ now: [+ Date.now(),+ {+ setNow: (_, { now }) => now,+ },+ ],}),loaders(({ values }) => ({@@ -446,9 +464,40 @@ export const webAnalyticsHealthLogic = kea<webAnalyticsHealthLogicType>([return urgentFailedChecks.length > 0},],++ refreshDisabledReason: [+ (s) => [s.nextRefreshAvailableAt, s.now],+ (nextRefreshAvailableAt: number | null, now: number): string | null => {+ if (nextRefreshAvailableAt === null || nextRefreshAvailableAt <= now) {+ return null+ }+ const secondsLeft = Math.ceil((nextRefreshAvailableAt - now) / 1000)+ return `A refresh just ran. Available again in ${humanFriendlyDuration(secondsLeft, { maxUnits: 2 })}`+ },+ ],}),- listeners(({ actions, values }) => ({+ listeners(({ actions, values, cache }) => ({+ setNextRefreshAvailableAt: ({ timestamp }) => {+ if (timestamp !== null && timestamp > Date.now()) {+ actions.startCooldownCountdown()+ }+ },+ startCooldownCountdown: () => {+ // Tick `now` once a second so the button's countdown stays live, and tear the+ // ticker down as soon as the cooldown clears. Re-adding with the same key replaces+ // any in-flight ticker, and the plugin pauses it while the tab is hidden.+ cache.disposables.add(() => {+ const intervalId = setInterval(() => {+ actions.setNow(Date.now())+ const { nextRefreshAvailableAt } = values+ if (nextRefreshAvailableAt === null || nextRefreshAvailableAt <= Date.now()) {+ cache.disposables.dispose('cooldownTicker')+ }+ }, 1000)+ return () => clearInterval(intervalId)+ }, 'cooldownTicker')+ },refreshHealthChecks: async ({ isManual }, breakpoint) => {const { overallHealthStatus } = valuesactions.reportWebAnalyticsHealthRefreshed({@@ -549,6 +598,10 @@ export const webAnalyticsHealthLogic = kea<webAnalyticsHealthLogicType>([const { nextRefreshAvailableAt } = valuesif (nextRefreshAvailableAt === null || nextRefreshAvailableAt <= Date.now()) {actions.refreshHealthChecks(false)+ } else {+ // A cooldown from a previous visit is still ticking down; keep the button's countdown live.+ actions.setNow(Date.now())+ actions.startCooldownCountdown()}}),])