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(frontend): load the cohort saved toast on demand (#126888)

Paul D'Ambrab23409d59df9
diff --git a/frontend/bin/check-eager-graph.mjs b/frontend/bin/check-eager-graph.mjs
index 1387e203b60b..335d65d4367a 100644
--- a/frontend/bin/check-eager-graph.mjs
+++ b/frontend/bin/check-eager-graph.mjs
@@ -104,8 +104,8 @@ const ROOTS = [
{
root: AUTHENTICATED_SHELL,
label: 'authenticated shell (every logged-in page)',
- // 2026-11-01: 4.11 MiB eager output, stable CSS included. ~0.3% headroom.
- budgetBytes: 4_320_000,
+ // 2026-11-01: 4.06 MiB eager output, stable CSS included. ~0.3% headroom.
+ budgetBytes: 4_270_000,
forbidden: [
'node_modules/monaco-editor/',
'products/product_analytics/frontend/insights/activityDescriptions',
@@ -127,6 +127,8 @@ const ROOTS = [
'src/layout/navigation/projectNoticeLogic.tsx',
// Only impersonating staff see this notice, and it pulls in react-draggable.
'src/layout/navigation/ImpersonationNotice/ImpersonationNotice.tsx',
+ // The cohort saved toast pulls in the workflows audience code and generated API clients.
+ 'src/scenes/cohorts/cohortSavedToast.ts',
// The wizard run card opens this drawer on click, and the drawer pulls in quill primitives.
'products/wizard/frontend/runs/WizardRunDetailsDrawer.tsx',
// The Today layout renders only behind the today-rail-nav flag, and it pulls in quill primitives.
@@ -190,8 +192,8 @@ const ROOTS = [
'src/scenes/project-homepage/today/TodayHome.tsx',
],
label: 'today home path',
- // 2026-11-01: 5.01 MiB, stable CSS included. ~0.3% headroom.
- budgetBytes: 5_270_000,
+ // 2026-11-01: 4.97 MiB, stable CSS included. ~0.3% headroom.
+ budgetBytes: 5_225_000,
forbidden: [
'src/scenes/project-homepage/ai-first/AiFirstHomepage.tsx',
'src/scenes/project-homepage/today/TodayReportPage.tsx',
@@ -209,7 +211,7 @@ const ROOTS = [
],
label: 'AI-first home path',
// 2026-11-01: 6.39 MiB, stable CSS included. ~1% headroom.
- budgetBytes: 6_770_000,
+ budgetBytes: 6_763_000,
forbidden: [
'products/posthog_ai/frontend/components/tool/widgets/VisualizationWidget.tsx',
'products/posthog_ai/frontend/components/tool/widgets/RecordingsWidget.tsx',
diff --git a/frontend/bin/layer-baseline.txt b/frontend/bin/layer-baseline.txt
index ca85bcd5dad7..6bb0156460d3 100644
--- a/frontend/bin/layer-baseline.txt
+++ b/frontend/bin/layer-baseline.txt
@@ -180,7 +180,6 @@ frontend/src/lib/components/EventPropertyTabs/EventPropertyTabs.tsx -> products/
frontend/src/lib/components/ExportButton/exportNudge.ts -> products/subscriptions/frontend/components/Subscriptions/exportNudge/ExportNudgeToast.tsx
frontend/src/lib/components/ExportButton/exportNudge.ts -> products/subscriptions/frontend/components/Subscriptions/exportNudge/exportNudgeLogic.ts
frontend/src/lib/components/ExportButton/exportNudge.ts -> products/subscriptions/frontend/components/Subscriptions/exportNudge/exportNudgeSubject.ts
-frontend/src/lib/components/ExportButton/exportsLogic.ts -> frontend/src/scenes/cohorts/cohortSavedToast.ts
frontend/src/lib/components/FlagCalledRebuildBanner/flagCalledDependencies.ts -> frontend/src/scenes/cohorts/CohortFilters/types.ts
frontend/src/lib/components/FlagCalledRebuildBanner/flagCalledDependencies.ts -> frontend/src/scenes/cohorts/cohortUtils.tsx
frontend/src/lib/components/FlagCalledRebuildBanner/flagCalledDependencies.ts -> frontend/src/scenes/feature-flags/flagEvaluationsTable.ts
diff --git a/frontend/src/lib/components/ExportButton/exportsLogic.test.ts b/frontend/src/lib/components/ExportButton/exportsLogic.test.ts
index 405f8510a89c..6720b23c5045 100644
--- a/frontend/src/lib/components/ExportButton/exportsLogic.test.ts
+++ b/frontend/src/lib/components/ExportButton/exportsLogic.test.ts
@@ -1,5 +1,7 @@
import api from 'lib/api'
import { lemonToast } from 'lib/lemon-ui/LemonToast'
+import { retryImport } from 'lib/utils/retryImport'
+import { cohortSavedToast } from 'scenes/cohorts/cohortSavedToast'
import { sidePanelStateLogic } from '~/layout/navigation-3000/sidepanel/sidePanelStateLogic'
import { initKeaTests } from '~/test/init'
@@ -45,6 +47,17 @@ jest.mock('products/subscriptions/frontend/components/Subscriptions/exportNudge/
jest.mock('products/subscriptions/frontend/components/Subscriptions/exportNudge/ExportNudgeToast', () => ({
claimExportNudgeMessage: jest.fn(() => null),
}))
+jest.mock('lib/utils/async', () => ({
+ ...jest.requireActual('lib/utils/async'),
+ delay: jest.fn(async () => {}),
+}))
+jest.mock('lib/utils/retryImport', () => ({
+ ...jest.requireActual('lib/utils/retryImport'),
+ retryImport: jest.fn((factory: () => unknown) => factory()),
+}))
+jest.mock('scenes/cohorts/cohortSavedToast', () => ({
+ cohortSavedToast: jest.fn(),
+}))
// The nudge body stands in as an opaque element that echoes the headline it was rendered under,
// which is what distinguishes the toast's states.
@@ -124,6 +137,35 @@ describe('exportsLogic', () => {
})
})
+ describe('createStaticCohort', () => {
+ it.each([
+ { toastLoads: true, expectedRichToasts: 1, expectedPlainToasts: 0 },
+ { toastLoads: false, expectedRichToasts: 0, expectedPlainToasts: 1 },
+ ])(
+ 'saves the cohort and confirms it when the toast loads: $toastLoads',
+ async ({ toastLoads, expectedRichToasts, expectedPlainToasts }) => {
+ jest.clearAllMocks()
+ if (!toastLoads) {
+ jest.mocked(retryImport).mockRejectedValueOnce(
+ new Error('Failed to fetch dynamically imported module')
+ )
+ }
+ const createSpy = jest.spyOn(api, 'create').mockResolvedValue({ id: 5, name: 'Buyers' })
+ initKeaTests()
+ const logic = exportsLogic()
+ logic.mount()
+
+ logic.actions.createStaticCohort('Buyers', { kind: 'HogQLQuery', query: 'select 1' } as any)
+ await new Promise((resolve) => setTimeout(resolve, 0))
+
+ expect(createSpy).toHaveBeenCalledTimes(1)
+ expect(lemonToast.error).not.toHaveBeenCalled()
+ expect(jest.mocked(cohortSavedToast).mock.calls).toHaveLength(expectedRichToasts)
+ expect(jest.mocked(lemonToast.success).mock.calls).toHaveLength(expectedPlainToasts)
+ }
+ )
+ })
+
describe('createExport toast', () => {
let logic: ReturnType<typeof exportsLogic.build>
diff --git a/frontend/src/lib/components/ExportButton/exportsLogic.ts b/frontend/src/lib/components/ExportButton/exportsLogic.ts
index 19062cc403c1..16dc5eaf0a88 100644
--- a/frontend/src/lib/components/ExportButton/exportsLogic.ts
+++ b/frontend/src/lib/components/ExportButton/exportsLogic.ts
@@ -17,7 +17,7 @@ import { lemonToast } from 'lib/lemon-ui/LemonToast'
import { ToastButton } from 'lib/lemon-ui/LemonToast/LemonToast'
import { delay } from 'lib/utils/async'
import { uuid } from 'lib/utils/dom'
-import { cohortSavedToast } from 'scenes/cohorts/cohortSavedToast'
+import { retryImport } from 'lib/utils/retryImport'
import type { SessionRecordingPlayerMode } from 'scenes/session-recordings/player/sessionRecordingPlayerLogic'
import { sidePanelStateLogic } from '~/layout/navigation-3000/sidepanel/sidePanelStateLogic'
@@ -383,6 +383,14 @@ export const exportsLogic = kea<exportsLogicType>([
const toastId = 'toast-' + Math.random()
try {
lemonToast.info('Saving cohort...', { toastId, autoClose: false })
+ // The toast pulls in the workflows audience code, so it loads on demand. A failed load
+ // must not stop the save or report a saved cohort as a failure.
+ const toastModule = retryImport(() => import('scenes/cohorts/cohortSavedToast')).catch(
+ (error: unknown) => {
+ posthog.captureException(error)
+ return null
+ }
+ )
// nosemgrep: prefer-codegen-api -- Legacy raw API call with a hand-written URL and an unchecked response type. Use cohortsCreate() from 'products/cohorts/frontend/generated/api' instead.
const cohort: CohortType = await api.create('api/cohort', {
is_static: true,
@@ -392,7 +400,12 @@ export const exportsLogic = kea<exportsLogicType>([
cohortsModel.findMounted()?.actions.cohortCreated(cohort)
await delay(500) // just in case the toast is too fast
lemonToast.dismiss(toastId)
- cohortSavedToast(cohort, 'query_results', `${toastId}-success`)
+ const savedToast = await toastModule
+ if (savedToast) {
+ savedToast.cohortSavedToast(cohort, 'query_results', `${toastId}-success`)
+ } else {
+ lemonToast.success('Cohort saved', { toastId: `${toastId}-success` })
+ }
} catch {
lemonToast.dismiss(toastId)
lemonToast.error('Cohort save failed')