Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

🐛 Fix crash when accessing poll that doesn’t exist anymore (#2218)

Luke Vella1f2cc63e86b8
diff --git a/apps/web/src/app/[locale]/(app)/(optional-space)/poll/[urlId]/layout.tsx b/apps/web/src/app/[locale]/(app)/(optional-space)/poll/[urlId]/layout.tsx
index 6dad1aa39..315eae3c0 100644
--- a/apps/web/src/app/[locale]/(app)/(optional-space)/poll/[urlId]/layout.tsx
+++ b/apps/web/src/app/[locale]/(app)/(optional-space)/poll/[urlId]/layout.tsx
@@ -2,10 +2,18 @@ import { prisma } from "@rallly/database";
import { dehydrate, HydrationBoundary } from "@tanstack/react-query";
import type { Metadata } from "next";
import { notFound, redirect } from "next/navigation";
+import { cache } from "react";
import { PollLayout } from "@/components/layouts/poll-layout";
import { createAuthenticatedSSRHelper } from "@/trpc/server/create-ssr-helper";
+const getPoll = cache((urlId: string) =>
+ prisma.poll.findUnique({
+ where: { id: urlId },
+ select: { title: true },
+ }),
+);
+
export default async function Layout(
props: React.PropsWithChildren<{ params: Promise<{ urlId: string }> }>,
) {
@@ -15,6 +23,12 @@ export default async function Layout(
const trpc = await createAuthenticatedSSRHelper();
+ const p = await getPoll(params.urlId);
+
+ if (!p) {
+ notFound();
+ }
+
// Prefetch all queries used in PollLayout
const [poll] = await Promise.all([
trpc.polls.get.fetch({ urlId: params.urlId }),
@@ -23,10 +37,6 @@ export default async function Layout(
trpc.polls.comments.list.prefetch({ pollId: params.urlId }),
]);
- if (!poll) {
- notFound();
- }
-
if (!poll.adminUrlId) {
redirect(`/invite/${params.urlId}`);
}
@@ -42,10 +52,7 @@ export async function generateMetadata(props: {
params: Promise<{ locale: string; urlId: string }>;
}): Promise<Metadata> {
const params = await props.params;
- const poll = await prisma.poll.findUnique({
- where: { id: params.urlId },
- select: { title: true },
- });
+ const poll = await getPoll(params.urlId);
if (!poll) {
notFound();
diff --git a/apps/web/tests/register-page.ts b/apps/web/tests/register-page.ts
index 6d740a21a..67a7d770f 100644
--- a/apps/web/tests/register-page.ts
+++ b/apps/web/tests/register-page.ts
@@ -8,7 +8,9 @@ export class RegisterPage {
async goto() {
await this.page.goto("/register");
- await this.page.getByText("Create Your Account").waitFor();
+ await this.page
+ .getByRole("heading", { name: "Create Your Account" })
+ .waitFor();
}
async register({
@@ -31,7 +33,9 @@ export class RegisterPage {
// Handle verification code
const code = await getCode(email);
- await this.page.getByText("Finish Logging In").waitFor();
+ await this.page
+ .getByRole("heading", { name: "Finish Logging In" })
+ .waitFor();
await this.page.getByPlaceholder("Enter your 6-digit code").fill(code);
// Verify successful registration