From c5ed1246a89e86f86bdba61be7131942c70b8e85 Mon Sep 17 00:00:00 2001 From: "vedanta.gawande" Date: Sat, 27 Jun 2026 01:16:42 +0000 Subject: [PATCH] Only reset export scope on genuine open transition via ref Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- .../data-grid/data-grid-export-dialog.tsx | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) 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";