From 8b18b86deb75c7925f462cdf3405b747ea421dea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl-Gerhard=20Lindesva=CC=88rd?= Date: Fri, 27 Feb 2026 09:37:29 +0100 Subject: [PATCH] fix: invalidate queries better --- apps/start/src/modals/add-dashboard.tsx | 2 +- apps/start/src/modals/save-report.tsx | 3 +++ .../routes/_app.$organizationId.$projectId.dashboards.tsx | 4 +++- ....$organizationId.$projectId.dashboards_.$dashboardId.tsx | 6 +++++- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/apps/start/src/modals/add-dashboard.tsx b/apps/start/src/modals/add-dashboard.tsx index 0e2fe008..bf8b6c10 100644 --- a/apps/start/src/modals/add-dashboard.tsx +++ b/apps/start/src/modals/add-dashboard.tsx @@ -47,7 +47,7 @@ export default function AddDashboard() { toast('Success', { description: 'Dashboard created.', }); - queryClient.invalidateQueries(trpc.dashboard.pathFilter()); + queryClient.invalidateQueries(trpc.dashboard.list.pathFilter()); popModal(); }, onError: handleError, diff --git a/apps/start/src/modals/save-report.tsx b/apps/start/src/modals/save-report.tsx index c59fdb0e..b478ddb2 100644 --- a/apps/start/src/modals/save-report.tsx +++ b/apps/start/src/modals/save-report.tsx @@ -56,6 +56,7 @@ export default function SaveReport({ projectId, }), ); + queryClient.invalidateQueries(trpc.dashboard.list.pathFilter()); const goToReport = () => { router.navigate({ @@ -157,6 +158,7 @@ function SelectDashboard({ projectId: string; }) { const trpc = useTRPC(); + const queryClient = useQueryClient(); const [isCreatingNew, setIsCreatingNew] = useState(false); const [newDashboardName, setNewDashboardName] = useState(''); @@ -177,6 +179,7 @@ function SelectDashboard({ trpc.dashboard.create.mutationOptions({ onError: handleError, async onSuccess(res) { + queryClient.invalidateQueries(trpc.dashboard.list.pathFilter()); await dashboardQuery.refetch(); onChange(res.id); setIsCreatingNew(false); diff --git a/apps/start/src/routes/_app.$organizationId.$projectId.dashboards.tsx b/apps/start/src/routes/_app.$organizationId.$projectId.dashboards.tsx index 7660d690..ec217388 100644 --- a/apps/start/src/routes/_app.$organizationId.$projectId.dashboards.tsx +++ b/apps/start/src/routes/_app.$organizationId.$projectId.dashboards.tsx @@ -29,7 +29,7 @@ import FullPageLoadingState from '@/components/full-page-loading-state'; import { PageContainer } from '@/components/page-container'; import { PageHeader } from '@/components/page-header'; import { handleErrorToastOptions, useTRPC } from '@/integrations/trpc/react'; -import { useMutation, useQuery } from '@tanstack/react-query'; +import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'; import { Link, createFileRoute } from '@tanstack/react-router'; export const Route = createFileRoute( @@ -58,6 +58,7 @@ export const Route = createFileRoute( function Component() { const { projectId } = Route.useParams(); const trpc = useTRPC(); + const queryClient = useQueryClient(); const query = useQuery( trpc.dashboard.list.queryOptions({ projectId, @@ -80,6 +81,7 @@ function Component() { })(error); }, onSuccess() { + queryClient.invalidateQueries(trpc.dashboard.list.pathFilter()); query.refetch(); toast('Success', { description: 'Dashboard deleted.', diff --git a/apps/start/src/routes/_app.$organizationId.$projectId.dashboards_.$dashboardId.tsx b/apps/start/src/routes/_app.$organizationId.$projectId.dashboards_.$dashboardId.tsx index 31e52d3c..db92f35a 100644 --- a/apps/start/src/routes/_app.$organizationId.$projectId.dashboards_.$dashboardId.tsx +++ b/apps/start/src/routes/_app.$organizationId.$projectId.dashboards_.$dashboardId.tsx @@ -35,7 +35,7 @@ import { } from '@/components/report/report-item'; import { handleErrorToastOptions, useTRPC } from '@/integrations/trpc/react'; import { pushModal, showConfirm } from '@/modals'; -import { useMutation, useQuery } from '@tanstack/react-query'; +import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'; import { createFileRoute, useRouter } from '@tanstack/react-router'; import { useCallback, useEffect, useState } from 'react'; @@ -85,6 +85,7 @@ function Component() { const router = useRouter(); const { organizationId, dashboardId, projectId } = Route.useParams(); const trpc = useTRPC(); + const queryClient = useQueryClient(); const { range, startDate, endDate, interval } = useOverviewOptions(); const dashboardQuery = useQuery( @@ -105,6 +106,7 @@ function Component() { trpc.dashboard.delete.mutationOptions({ onError: handleErrorToastOptions({}), onSuccess() { + queryClient.invalidateQueries(trpc.dashboard.list.pathFilter()); toast('Dashboard deleted'); router.navigate({ to: '/$organizationId/$projectId/dashboards', @@ -139,6 +141,7 @@ function Component() { trpc.report.delete.mutationOptions({ onError: handleErrorToastOptions({}), onSuccess() { + queryClient.invalidateQueries(trpc.dashboard.list.pathFilter()); reportsQuery.refetch(); toast('Report deleted'); }, @@ -149,6 +152,7 @@ function Component() { trpc.report.duplicate.mutationOptions({ onError: handleErrorToastOptions({}), onSuccess() { + queryClient.invalidateQueries(trpc.dashboard.list.pathFilter()); reportsQuery.refetch(); toast('Report duplicated'); },