From 44c32737ebd67897189c527e482931fd788dc85e Mon Sep 17 00:00:00 2001 From: Dhruwang Date: Wed, 20 May 2026 17:28:54 +0530 Subject: [PATCH] fix: invalidate React Query cache after duplicate so list shows new draft MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit router.refresh() only re-runs server components — the surveys overview list is hydrated client-side via use-surveys (React Query useInfiniteQuery), so its cache stayed stale and the new draft only appeared after a manual page refresh. Match the use-delete-survey pattern: grab queryClient and invalidate surveyKeys.lists() after the duplicate action resolves. Same key prefix the delete flow uses. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../survey/list/components/survey-dropdown-menu.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/apps/web/modules/survey/list/components/survey-dropdown-menu.tsx b/apps/web/modules/survey/list/components/survey-dropdown-menu.tsx index 028db3ced1..16cb556faf 100644 --- a/apps/web/modules/survey/list/components/survey-dropdown-menu.tsx +++ b/apps/web/modules/survey/list/components/survey-dropdown-menu.tsx @@ -1,5 +1,6 @@ "use client"; +import { useQueryClient } from "@tanstack/react-query"; import { CopyIcon, EyeIcon, LinkIcon, MoreVertical, SquarePenIcon, TrashIcon } from "lucide-react"; import Link from "next/link"; import { useRouter } from "next/navigation"; @@ -14,6 +15,7 @@ import { getV3ApiErrorMessage } from "@/modules/api/lib/v3-client"; import { EditPublicSurveyAlertDialog } from "@/modules/survey/components/edit-public-survey-alert-dialog"; import { copySurveyLink } from "@/modules/survey/lib/client-utils"; import { copySurveyToOtherWorkspaceAction } from "@/modules/survey/list/actions"; +import { surveyKeys } from "@/modules/survey/list/lib/query"; import { TSurveyListItem } from "@/modules/survey/list/types/survey-overview"; import { DeleteDialog } from "@/modules/ui/components/delete-dialog"; import { @@ -48,6 +50,7 @@ export const SurveyDropDownMenu = ({ const [isDropDownOpen, setIsDropDownOpen] = useState(false); const [isCautionDialogOpen, setIsCautionDialogOpen] = useState(false); const router = useRouter(); + const queryClient = useQueryClient(); const editHref = `/workspaces/${workspace?.id}/surveys/${survey.id}/edit`; @@ -99,7 +102,10 @@ export const SurveyDropDownMenu = ({ }); if (response?.data) { toast.success(t("workspace.surveys.survey_duplicated_successfully")); - router.refresh(); + // The list is fetched via React Query (see use-surveys.ts); router.refresh() + // alone won't repopulate the client cache. Invalidate the lists prefix to + // trigger a refetch so the new draft appears. + await queryClient.invalidateQueries({ queryKey: surveyKeys.lists() }); return; } toast.error(getFormattedErrorMessage(response));