Skip to content

: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.

chore(insights): deflake the long-loading visual regression story (#89694)

Paul D'Ambrafb04f6571e93
diff --git a/frontend/src/lib/lemon-ui/LoadingBar/LoadingBar.tsx b/frontend/src/lib/lemon-ui/LoadingBar/LoadingBar.tsx
index 4364504366ab..4e943116cff3 100644
--- a/frontend/src/lib/lemon-ui/LoadingBar/LoadingBar.tsx
+++ b/frontend/src/lib/lemon-ui/LoadingBar/LoadingBar.tsx
@@ -4,6 +4,10 @@ import { useEffect, useState } from 'react'
import { usePageVisibility } from 'lib/hooks/usePageVisibility'
import { cn } from 'lib/utils/css-classes'
+import { inStorybook, inStorybookTestRunner } from 'lib/utils/dom'
+
+// atan(1) / (PI / 2) puts the frozen Storybook bar at a 50% fill
+const STORYBOOK_FROZEN_PROGRESS = 1
export interface SpinnerProps {
textColored?: boolean
@@ -20,6 +24,9 @@ export interface SpinnerProps {
export function LoadingBar({ className, loadId, setProgress, progress, wrapperClassName }: SpinnerProps): JSX.Element {
const [_progress, _setProgress] = useState(0)
const { isVisible: isPageVisible } = usePageVisibility()
+ // The 50ms ticker below moves the fill on every frame, which makes each
+ // Storybook visual regression capture differ. Freeze the fill there instead.
+ const frozenForStorybook = inStorybook() || inStorybookTestRunner()
useEffect(() => {
if (loadId && progress) {
@@ -36,7 +43,7 @@ export function LoadingBar({ className, loadId, setProgress, progress, wrapperCl
}, [_progress, loadId, setProgress])
useEffect(() => {
- if (!isPageVisible) {
+ if (!isPageVisible || frozenForStorybook) {
return
}
@@ -58,7 +65,9 @@ export function LoadingBar({ className, loadId, setProgress, progress, wrapperCl
}, 50)
return () => clearInterval(interval)
- }, [loadId, isPageVisible])
+ }, [loadId, isPageVisible, frozenForStorybook])
+
+ const displayProgress = frozenForStorybook ? STORYBOOK_FROZEN_PROGRESS : _progress
return (
<div className={cn(`progress-outer max-w-120 w-full my-3`, wrapperClassName)} data-attr="loading-bar">
@@ -66,7 +75,9 @@ export function LoadingBar({ className, loadId, setProgress, progress, wrapperCl
<div
className="progress-bar"
// eslint-disable-next-line react/forbid-dom-props
- style={{ width: Math.round((Math.atan(_progress) / (Math.PI / 2)) * 100 * 1000) / 1000 + '%' }}
+ style={{
+ width: Math.round((Math.atan(displayProgress) / (Math.PI / 2)) * 100 * 1000) / 1000 + '%',
+ }}
/>
</div>
</div>
diff --git a/frontend/src/queries/nodes/DataNode/dataNodeLogic.ts b/frontend/src/queries/nodes/DataNode/dataNodeLogic.ts
index e2dab80972b7..a627b013f3c5 100644
--- a/frontend/src/queries/nodes/DataNode/dataNodeLogic.ts
+++ b/frontend/src/queries/nodes/DataNode/dataNodeLogic.ts
@@ -22,7 +22,7 @@ import posthog from 'posthog-js'
import api, { ApiMethodOptions } from 'lib/api'
import { dayjs } from 'lib/dayjs'
import { ConcurrencyController } from 'lib/utils/concurrencyController'
-import { uuid } from 'lib/utils/dom'
+import { inStorybook, inStorybookTestRunner, uuid } from 'lib/utils/dom'
import { shouldCancelQuery } from 'lib/utils/requests'
import { UNSAVED_INSIGHT_MIN_REFRESH_INTERVAL_MINUTES } from 'scenes/insights/insightLogic'
import { compareDataNodeQuery, haveVariablesOrFiltersChanged, validateQuery } from 'scenes/insights/utils/queryUtils'
@@ -144,6 +144,10 @@ export interface DataNodeLogicProps {
export const AUTOLOAD_INTERVAL = 30000
const LOAD_MORE_ROWS_LIMIT = 10000
+// Loading and error states render the query id, so a random id per load
+// makes Storybook visual regression captures differ on every run
+const STORYBOOK_QUERY_ID = '00000000-0000-4000-8000-000000000000'
+
const VALID_REFRESH_TYPES: ReadonlySet<RefreshType> = new Set([
'async',
'async_except_on_cache_miss',
@@ -933,7 +937,7 @@ export const dataNodeLogic = kea<dataNodeLogicType>([
overrideQuery?: DataNode<Record<string, any>>
) => ({
refresh: sanitizeRefreshType(refresh),
- queryId: alreadyRunningQueryId || uuid(),
+ queryId: alreadyRunningQueryId || (inStorybook() || inStorybookTestRunner() ? STORYBOOK_QUERY_ID : uuid()),
pollOnly: !!alreadyRunningQueryId,
overrideQuery,
}),