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.

fix(exports): show immediate feedback when downloading an export (#73305)

Phill34ed88861e7d
diff --git a/frontend/src/lib/components/ExportButton/exportsLogic.test.ts b/frontend/src/lib/components/ExportButton/exportsLogic.test.ts
index 1ae9e9b2c6fb..70ae280b97cb 100644
--- a/frontend/src/lib/components/ExportButton/exportsLogic.test.ts
+++ b/frontend/src/lib/components/ExportButton/exportsLogic.test.ts
@@ -262,9 +262,15 @@ describe('exportsLogic', () => {
label: 'clears the highlight when the download succeeds',
downloadOk: true,
remainingIds: [] as number[],
+ expectsDismiss: false,
},
- { label: 'keeps the highlight when the download fails', downloadOk: false, remainingIds: [41] },
- ])('downloadExport $label', async ({ downloadOk, remainingIds }) => {
+ {
+ label: 'keeps the highlight and drops the generic toast when the download fails',
+ downloadOk: false,
+ remainingIds: [41],
+ expectsDismiss: true,
+ },
+ ])('downloadExport $label', async ({ downloadOk, remainingIds, expectsDismiss }) => {
const tracked = asset({ id: 41, export_format: ExporterFormat.MP4, has_content: true })
logic.actions.addFresh(tracked)
jest.mocked(downloadExportedAsset).mockResolvedValueOnce(downloadOk)
@@ -274,6 +280,14 @@ describe('exportsLogic', () => {
expect(jest.mocked(downloadExportedAsset).mock.calls).toEqual([[tracked]])
expect(logic.values.freshUndownloadedExports.map((a) => a.id)).toEqual(remainingIds)
+ // The spinner is shown immediately so the button doesn't look dead during the blocking probe.
+ expect(lemonToast.promise).toHaveBeenCalledWith(
+ expect.any(Promise),
+ expect.objectContaining({ pending: 'Preparing download…' }),
+ expect.objectContaining({ toastId: expect.any(String) })
+ )
+ // On failure downloadExportedAsset shows its own specific toast, so the generic one is dismissed.
+ expect(jest.mocked(lemonToast.dismiss).mock.calls.length > 0).toBe(expectsDismiss)
})
it('surfaces the failure and stops tracking when a tracked async export fails', async () => {
diff --git a/frontend/src/lib/components/ExportButton/exportsLogic.ts b/frontend/src/lib/components/ExportButton/exportsLogic.ts
index add95c9ee2d9..8a03a007b9f4 100644
--- a/frontend/src/lib/components/ExportButton/exportsLogic.ts
+++ b/frontend/src/lib/components/ExportButton/exportsLogic.ts
@@ -257,10 +257,34 @@ export const exportsLogic = kea<exportsLogicType>([
actions.loadExports()
},
downloadExport: async ({ exportedAsset }) => {
- // Only drop the "not downloaded" highlight once the file actually downloads, so a
- // failed retrieval leaves the user a retry cue instead of a silent dead end.
- if (await downloadExportedAsset(exportedAsset)) {
- actions.removeFresh(exportedAsset)
+ // Downloading a synchronous export blocks server-side while the content is generated,
+ // and downloadExportedAsset probes the endpoint before navigating — that wait can run
+ // for a minute or more. Drive it through lemonToast.promise so the user sees a spinner
+ // immediately instead of a button that looks like it did nothing until the download starts.
+ const downloadToastId = 'download-' + uuid()
+ try {
+ await lemonToast.promise(
+ (async (): Promise<string> => {
+ // Only drop the "not downloaded" highlight once the file actually downloads, so a
+ // failed retrieval leaves the user a retry cue instead of a silent dead end.
+ if (!(await downloadExportedAsset(exportedAsset))) {
+ throw new Error(EXPORT_DOWNLOAD_FAILED)
+ }
+ actions.removeFresh(exportedAsset)
+ return 'Download started'
+ })(),
+ {
+ pending: 'Preparing download…',
+ success: 'Download started',
+ error: 'Download failed',
+ },
+ { toastId: downloadToastId }
+ )
+ } catch (error) {
+ if (error instanceof Error && error.message === EXPORT_DOWNLOAD_FAILED) {
+ // downloadExportedAsset already surfaced a specific error toast — drop the generic one.
+ lemonToast.dismiss(downloadToastId)
+ }
}
},
loadExportsSuccess: async ({ exports: exportsList }, breakpoint) => {