Skip to content

Open-source status page, incident response and uptime monitoring

fix: trpc hydration error (#1667)

Maximilian Kaske9009d5503d3e
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),