From 9009d5503d3e35bec0fb1515ef1a03686dae5e0b Mon Sep 17 00:00:00 2001 From: Maximilian Kaske <56969857+mxkaske@users.noreply.github.com> Date: Fri, 19 Dec 2025 10:02:55 +0100 Subject: [PATCH] fix: trpc hydration error (#1667) * fix: trpc query enable * ci: apply automated fixes * fix: log * fix: trpc enable query --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- .../(status-page)/[domain]/(public)/page.tsx | 16 +++++---- packages/db/src/schema/shared.ts | 35 ++++++------------- 2 files changed, 20 insertions(+), 31 deletions(-) diff --git a/apps/status-page/src/app/(status-page)/[domain]/(public)/page.tsx b/apps/status-page/src/app/(status-page)/[domain]/(public)/page.tsx index edb30978e..923e57ad9 100644 --- a/apps/status-page/src/app/(status-page)/[domain]/(public)/page.tsx +++ b/apps/status-page/src/app/(status-page)/[domain]/(public)/page.tsx @@ -38,11 +38,12 @@ export default function Page() { // NOTE: we cannot use `cardType` and `barType` here because of queryKey changes // It wouldn't match the server prefetch keys and we would have to refetch the page here - const { data: pageInitial, error } = useQuery( - trpc.statusPage.get.queryOptions({ + const { data: pageInitial, error } = useQuery({ + ...trpc.statusPage.get.queryOptions({ slug: domain, }), - ); + enabled: !!domain, + }); // Handle case where page doesn't exist or query fails if (error || (!pageInitial && domain)) { @@ -61,19 +62,20 @@ export default function Page() { cardType, barType, }), - enabled: hasCustomConfig, + enabled: !!domain && hasCustomConfig, }); // NOTE: we can prefetch that to avoid loading state - const { data: uptimeData, isLoading } = useQuery( - trpc.statusPage.getUptime.queryOptions({ + const { data: uptimeData, isLoading } = useQuery({ + ...trpc.statusPage.getUptime.queryOptions({ slug: domain, monitorIds: pageInitial?.monitors?.map((monitor) => monitor.id.toString()) || [], cardType, barType, }), - ); + enabled: !!pageInitial && pageInitial.monitors.length > 0, + }); // NOTE: we need to filter out the incidents as we don't want to show all of them in the banner - a single one is enough // REMINDER: we could move that to the server - but we might wanna have the info of all openEvents actually diff --git a/packages/db/src/schema/shared.ts b/packages/db/src/schema/shared.ts index ece3f498b..caccb1a30 100644 --- a/packages/db/src/schema/shared.ts +++ b/packages/db/src/schema/shared.ts @@ -114,35 +114,22 @@ const trackersSchema = z ) .default([]); +export const statusPageEventSchema = z.object({ + id: z.number(), + name: z.string(), + from: z.date(), + to: z.date().nullable(), + status: z.enum(["success", "degraded", "error", "info"]).default("success"), + type: z.enum(["maintenance", "incident", "report"]), +}); + export const selectPublicPageSchemaWithRelation = selectPageSchema.extend({ monitorGroups: selectMonitorGroupSchema.array().default([]), // TODO: include status of the monitor monitors: selectPublicMonitorWithStatusSchema.array(), trackers: trackersSchema, - lastEvents: z.array( - z.object({ - id: z.number(), - name: z.string(), - from: z.date(), - to: z.date().nullable(), - status: z - .enum(["success", "degraded", "error", "info"]) - .default("success"), - type: z.enum(["maintenance", "incident", "report"]), - }), - ), - openEvents: z.array( - z.object({ - id: z.number(), - name: z.string(), - from: z.date(), - to: z.date().nullable(), - status: z - .enum(["success", "degraded", "error", "info"]) - .default("success"), - type: z.enum(["maintenance", "incident", "report"]), - }), - ), + lastEvents: z.array(statusPageEventSchema), + openEvents: z.array(statusPageEventSchema), statusReports: z.array(selectStatusReportPageSchema), incidents: z.array(selectIncidentSchema), maintenances: z.array(selectMaintenancePageSchema), -- 2.54.0