Openstatus www.openstatus.dev

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>

authored by

Maximilian Kaske
autofix-ci[bot]
and committed by
GitHub
9009d550 d7475c56

+20 -31
+9 -7
apps/status-page/src/app/(status-page)/[domain]/(public)/page.tsx
··· 38 38 39 39 // NOTE: we cannot use `cardType` and `barType` here because of queryKey changes 40 40 // It wouldn't match the server prefetch keys and we would have to refetch the page here 41 - const { data: pageInitial, error } = useQuery( 42 - trpc.statusPage.get.queryOptions({ 41 + const { data: pageInitial, error } = useQuery({ 42 + ...trpc.statusPage.get.queryOptions({ 43 43 slug: domain, 44 44 }), 45 - ); 45 + enabled: !!domain, 46 + }); 46 47 47 48 // Handle case where page doesn't exist or query fails 48 49 if (error || (!pageInitial && domain)) { ··· 61 62 cardType, 62 63 barType, 63 64 }), 64 - enabled: hasCustomConfig, 65 + enabled: !!domain && hasCustomConfig, 65 66 }); 66 67 67 68 // NOTE: we can prefetch that to avoid loading state 68 - const { data: uptimeData, isLoading } = useQuery( 69 - trpc.statusPage.getUptime.queryOptions({ 69 + const { data: uptimeData, isLoading } = useQuery({ 70 + ...trpc.statusPage.getUptime.queryOptions({ 70 71 slug: domain, 71 72 monitorIds: 72 73 pageInitial?.monitors?.map((monitor) => monitor.id.toString()) || [], 73 74 cardType, 74 75 barType, 75 76 }), 76 - ); 77 + enabled: !!pageInitial && pageInitial.monitors.length > 0, 78 + }); 77 79 78 80 // 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 79 81 // REMINDER: we could move that to the server - but we might wanna have the info of all openEvents actually
+11 -24
packages/db/src/schema/shared.ts
··· 114 114 ) 115 115 .default([]); 116 116 117 + export const statusPageEventSchema = z.object({ 118 + id: z.number(), 119 + name: z.string(), 120 + from: z.date(), 121 + to: z.date().nullable(), 122 + status: z.enum(["success", "degraded", "error", "info"]).default("success"), 123 + type: z.enum(["maintenance", "incident", "report"]), 124 + }); 125 + 117 126 export const selectPublicPageSchemaWithRelation = selectPageSchema.extend({ 118 127 monitorGroups: selectMonitorGroupSchema.array().default([]), 119 128 // TODO: include status of the monitor 120 129 monitors: selectPublicMonitorWithStatusSchema.array(), 121 130 trackers: trackersSchema, 122 - lastEvents: z.array( 123 - z.object({ 124 - id: z.number(), 125 - name: z.string(), 126 - from: z.date(), 127 - to: z.date().nullable(), 128 - status: z 129 - .enum(["success", "degraded", "error", "info"]) 130 - .default("success"), 131 - type: z.enum(["maintenance", "incident", "report"]), 132 - }), 133 - ), 134 - openEvents: z.array( 135 - z.object({ 136 - id: z.number(), 137 - name: z.string(), 138 - from: z.date(), 139 - to: z.date().nullable(), 140 - status: z 141 - .enum(["success", "degraded", "error", "info"]) 142 - .default("success"), 143 - type: z.enum(["maintenance", "incident", "report"]), 144 - }), 145 - ), 131 + lastEvents: z.array(statusPageEventSchema), 132 + openEvents: z.array(statusPageEventSchema), 146 133 statusReports: z.array(selectStatusReportPageSchema), 147 134 incidents: z.array(selectIncidentSchema), 148 135 maintenances: z.array(selectMaintenancePageSchema),