Skip to content

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

πŸ› Fix dev SSR bailout on the profile settings page (#2868)

Luke Vella0e33432d2897
diff --git a/apps/web/src/app/[locale]/(space)/settings/profile/components/delete-account-button.tsx b/apps/web/src/app/[locale]/(space)/settings/profile/components/delete-account-button.tsx
deleted file mode 100644
index ebd1fd0c9..000000000
--- a/apps/web/src/app/[locale]/(space)/settings/profile/components/delete-account-button.tsx
+++ /dev/null
@@ -1,26 +0,0 @@
-"use client";
-
-import { Button } from "@rallly/ui/button";
-import { useDialog } from "@rallly/ui/dialog";
-
-import { Trans } from "@/i18n/client";
-import { DeleteAccountDialog } from "./delete-account-dialog";
-
-export function DeleteAccountButton({
- summary,
- ...rest
-}: {
- summary?: React.ReactNode;
- "aria-labelledby"?: string;
- "aria-describedby"?: string;
-}) {
- const dialog = useDialog();
- return (
- <>
- <Button className="text-destructive" {...dialog.triggerProps} {...rest}>
- <Trans i18nKey="deleteAccount" defaults="Delete Account" />
- </Button>
- <DeleteAccountDialog {...dialog.dialogProps} summary={summary} />
- </>
- );
-}
diff --git a/apps/web/src/app/[locale]/(space)/settings/profile/components/delete-account-dialog.tsx b/apps/web/src/app/[locale]/(space)/settings/profile/components/delete-account-dialog.tsx
index f97fa4788..e76c83333 100644
--- a/apps/web/src/app/[locale]/(space)/settings/profile/components/delete-account-dialog.tsx
+++ b/apps/web/src/app/[locale]/(space)/settings/profile/components/delete-account-dialog.tsx
@@ -1,6 +1,5 @@
"use client";
import { Button } from "@rallly/ui/button";
-import type { DialogProps } from "@rallly/ui/dialog";
import {
Dialog,
DialogClose,
@@ -9,6 +8,8 @@ import {
DialogFooter,
DialogHeader,
DialogTitle,
+ DialogTrigger,
+ useDialog,
} from "@rallly/ui/dialog";
import { Form, FormField, FormItem, FormMessage } from "@rallly/ui/form";
import { Input } from "@rallly/ui/input";
@@ -21,11 +22,11 @@ import { isSelfHosted } from "@/lib/constants";
import { useSafeAction } from "@/lib/safe-action/client";
import { deleteAccountAction, scheduleAccountDeletionAction } from "../actions";
-export function DeleteAccountDialog(
- props: DialogProps & {
- summary?: React.ReactNode;
- },
-) {
+export function DeleteAccountDialog(props: {
+ /** Rendered as the dialog trigger; the caller styles it and wires aria labels. */
+ trigger: React.ReactElement;
+ summary?: React.ReactNode;
+}) {
if (isSelfHosted) {
return <InstantDeleteAccountDialog {...props} />;
}
@@ -34,19 +35,22 @@ export function DeleteAccountDialog(
}
function ScheduleAccountDeletionDialog({
+ trigger,
summary,
- ...rest
-}: DialogProps & {
+}: {
+ trigger: React.ReactElement;
summary?: React.ReactNode;
}) {
+ const dialog = useDialog();
const scheduleAccountDeletion = useSafeAction(scheduleAccountDeletionAction, {
onSuccess: () => {
- rest.onOpenChange?.(false);
+ dialog.dismiss();
},
});
return (
- <Dialog {...rest}>
+ <Dialog {...dialog.dialogProps}>
+ <DialogTrigger render={trigger} />
<DialogContent>
<DialogHeader>
<DialogTitle>
@@ -98,11 +102,13 @@ function ScheduleAccountDeletionDialog({
// Self-hosted instances delete immediately β€” no reaper, no recovery window β€”
// so the email confirmation step guards against an irreversible mistake.
function InstantDeleteAccountDialog({
+ trigger,
summary,
- ...rest
-}: DialogProps & {
+}: {
+ trigger: React.ReactElement;
summary?: React.ReactNode;
}) {
+ const dialog = useDialog();
const user = useAuthedUser();
const { t } = useTranslation();
const form = useForm<{ email: string }>({
@@ -125,7 +131,8 @@ function InstantDeleteAccountDialog({
return (
<Form {...form}>
- <Dialog {...rest}>
+ <Dialog {...dialog.dialogProps}>
+ <DialogTrigger render={trigger} />
<DialogContent>
<form
onSubmit={form.handleSubmit(async () => {
diff --git a/apps/web/src/app/[locale]/(space)/settings/profile/components/delete-account-setting.tsx b/apps/web/src/app/[locale]/(space)/settings/profile/components/delete-account-setting.tsx
index 3332aa0e6..73615e560 100644
--- a/apps/web/src/app/[locale]/(space)/settings/profile/components/delete-account-setting.tsx
+++ b/apps/web/src/app/[locale]/(space)/settings/profile/components/delete-account-setting.tsx
@@ -1,9 +1,10 @@
+import { Button } from "@rallly/ui/button";
import { TriangleAlertIcon } from "lucide-react";
import {
- Setting,
SettingControl,
SettingDescription,
SettingIcon,
+ SettingRow,
SettingTitle,
} from "@/components/setting";
import { getScheduledDeletionDate } from "@/features/user/account-deletion/utils";
@@ -11,6 +12,10 @@ import { Trans } from "@/i18n/client";
import { getSession } from "@/lib/auth";
import { formatDateTime } from "@/lib/datetime/format";
import { CancelAccountDeletionButton } from "./cancel-account-deletion-button";
+import { DeleteAccountDialog } from "./delete-account-dialog";
+
+const pendingDeletionTitleId = "pending-deletion-title";
+const pendingDeletionDescriptionId = "pending-deletion-description";
export async function PendingDeletionSetting({
deletedAt,
@@ -25,14 +30,14 @@ export async function PendingDeletionSetting({
});
return (
- <Setting>
+ <SettingRow>
<SettingIcon>
<TriangleAlertIcon />
</SettingIcon>
- <SettingTitle>
+ <SettingTitle id={pendingDeletionTitleId}>
<Trans i18nKey="deleteAccount" defaults="Delete Account" />
</SettingTitle>
- <SettingDescription>
+ <SettingDescription id={pendingDeletionDescriptionId}>
<Trans
i18nKey="pendingDeletionNotice"
defaults="Your account and data will be permanently deleted on {deletionDate}."
@@ -40,35 +45,51 @@ export async function PendingDeletionSetting({
/>
</SettingDescription>
<SettingControl>
- <CancelAccountDeletionButton />
+ <CancelAccountDeletionButton
+ aria-labelledby={pendingDeletionTitleId}
+ aria-describedby={pendingDeletionDescriptionId}
+ />
</SettingControl>
- </Setting>
+ </SettingRow>
);
}
+const deleteAccountTitleId = "delete-account-title";
+const deleteAccountDescriptionId = "delete-account-description";
+
export function DeleteAccountSetting({
- children,
+ summary,
}: {
- children: React.ReactElement<{
- "aria-labelledby"?: string;
- "aria-describedby"?: string;
- }>;
+ summary?: React.ReactNode;
}) {
return (
- <Setting>
+ <SettingRow>
<SettingIcon>
<TriangleAlertIcon />
</SettingIcon>
- <SettingTitle>
+ <SettingTitle id={deleteAccountTitleId}>
<Trans i18nKey="deleteAccount" defaults="Delete Account" />
</SettingTitle>
- <SettingDescription>
+ <SettingDescription id={deleteAccountDescriptionId}>
<Trans
i18nKey="dangerZoneAccountDeletion"
defaults="Delete your account and all data associated with it"
/>
</SettingDescription>
- <SettingControl>{children}</SettingControl>
- </Setting>
+ <SettingControl>
+ <DeleteAccountDialog
+ trigger={
+ <Button
+ className="text-destructive"
+ aria-labelledby={deleteAccountTitleId}
+ aria-describedby={deleteAccountDescriptionId}
+ >
+ <Trans i18nKey="deleteAccount" defaults="Delete Account" />
+ </Button>
+ }
+ summary={summary}
+ />
+ </SettingControl>
+ </SettingRow>
);
}
diff --git a/apps/web/src/app/[locale]/(space)/settings/profile/page.tsx b/apps/web/src/app/[locale]/(space)/settings/profile/page.tsx
index db3d70585..03e8266e6 100644
--- a/apps/web/src/app/[locale]/(space)/settings/profile/page.tsx
+++ b/apps/web/src/app/[locale]/(space)/settings/profile/page.tsx
@@ -28,7 +28,6 @@ import {
AccountDeletionSummary,
AccountDeletionSummarySkeleton,
} from "./components/account-deletion-summary";
-import { DeleteAccountButton } from "./components/delete-account-button";
import {
DeleteAccountSetting,
PendingDeletionSetting,
@@ -99,15 +98,13 @@ export default async function Page() {
{user.deletedAt ? (
<PendingDeletionSetting deletedAt={user.deletedAt} />
) : (
- <DeleteAccountSetting>
- <DeleteAccountButton
- summary={
- <Suspense fallback={<AccountDeletionSummarySkeleton />}>
- <AccountDeletionSummary />
- </Suspense>
- }
- />
- </DeleteAccountSetting>
+ <DeleteAccountSetting
+ summary={
+ <Suspense fallback={<AccountDeletionSummarySkeleton />}>
+ <AccountDeletionSummary />
+ </Suspense>
+ }
+ />
)}
</SettingsGroup>
</PageSectionContent>
diff --git a/apps/web/src/components/setting.tsx b/apps/web/src/components/setting.tsx
index 1081db563..cf9399d7e 100644
--- a/apps/web/src/components/setting.tsx
+++ b/apps/web/src/components/setting.tsx
@@ -102,11 +102,14 @@ export const SettingIcon = ({ children }: React.PropsWithChildren) => {
);
};
-export const SettingTitle = ({ children }: React.PropsWithChildren) => {
+export const SettingTitle = ({
+ children,
+ id,
+}: React.PropsWithChildren<{ id?: string }>) => {
const { titleId } = useSetting();
return (
<div
- id={titleId}
+ id={id ?? titleId}
className="flex items-center gap-x-2 text-sm [grid-area:title]"
>
{children}
@@ -114,11 +117,14 @@ export const SettingTitle = ({ children }: React.PropsWithChildren) => {
);
};
-export const SettingDescription = ({ children }: React.PropsWithChildren) => {
+export const SettingDescription = ({
+ children,
+ id,
+}: React.PropsWithChildren<{ id?: string }>) => {
const { descriptionId } = useSetting();
return (
<div
- id={descriptionId}
+ id={id ?? descriptionId}
className="mt-0.5 text-muted-foreground text-xs [grid-area:description]"
>
{children}
@@ -131,6 +137,10 @@ export const SettingDescription = ({ children }: React.PropsWithChildren) => {
* element, so the row's title and description are applied to it directly.
* Inside `SettingRow` there is no single element to label β€” the control names
* itself with `useSettingLabels()` β€” so the child is rendered untouched.
+ *
+ * Inside `Setting` the child must be created in client code: cloneElement
+ * corrupts elements streamed from server components (dev SSR bails out with
+ * "Element type is invalid"). Server-composed controls go in `SettingRow`.
*/
export const SettingControl = ({
children,