diff --git a/packages/dashboard-ui-components/src/components/data-grid/data-grid-export-dialog.tsx b/packages/dashboard-ui-components/src/components/data-grid/data-grid-export-dialog.tsx index cde2c462e..249b158a7 100644 --- a/packages/dashboard-ui-components/src/components/data-grid/data-grid-export-dialog.tsx +++ b/packages/dashboard-ui-components/src/components/data-grid/data-grid-export-dialog.tsx @@ -1,7 +1,7 @@ "use client"; import { DownloadSimpleIcon } from "@phosphor-icons/react"; -import React, { useCallback, useEffect, useMemo, useState } from "react"; +import React, { useCallback, useEffect, useMemo, useRef, useState } from "react"; import { DesignButton } from "../button"; import { DesignDialog } from "../dialog"; @@ -69,14 +69,19 @@ export function DataGridExportDialog({ // Reset the scope to its default each time the dialog opens. The dialog stays // mounted between opens, so without this the scope would retain whatever the - // user last picked instead of honoring `defaultScope` on every open. We key - // off `open` so this only fires on an open transition. + // user last picked instead of honoring `defaultScope` on every open. We track + // the previous `open` value with a ref so the reset only fires on a genuine + // closed->open transition -- not on every render that flips other state (e.g. + // `isExporting` going false after a failed/empty export would otherwise wipe + // the user's current selection while the dialog is still open). const defaultScope = exportOptions?.defaultScope ?? "all"; + const wasOpenRef = useRef(false); useEffect(() => { - if (open && !isExporting) { + if (open && !wasOpenRef.current) { setScope(defaultScope); } - }, [open, isExporting, defaultScope]); + wasOpenRef.current = open; + }, [open, defaultScope]); const entityName = exportOptions?.entityName ?? "row"; const entityNamePlural = exportOptions?.entityNamePlural ?? "rows";