Compare commits

..
Author SHA1 Message Date
Thomas 78c514ff8a Merge branch 'dev' into app-edit-nav-deadlock 2026-07-06 03:03:28 +02:00
ajnart 0138e4659e fix(forms): stabilize AppForm initialize effect deps to fix edit page render loop
The useEffect that re-initializes the form when initialValues change had
`form` in its dependency array. Mantine's useForm returns a fresh form
object literal on every render, so the effect re-ran every render. The
outer form.initialize() wrapper always calls handleValuesChanges() ->
$errors.clearErrors() -> setErrorsState({}) (a new object), which
triggers a re-render and loops infinitely. The resulting
"Maximum update depth exceeded" error swallows all interactions,
including sidebar link clicks, so router.push is interrupted and Next.js
reports "navigation was cancelled" (issue #6198).

initialValuesKey is a primitive string built from the initialValues
fields, so it already covers the only case the effect exists for:
re-initializing when initialValues actually changes (e.g. navigating
between edit pages).

Reported on v1.69.0/1.69.1, Edge and Chromium.
2026-07-06 03:00:32 +02:00
13 changed files with 9 additions and 182 deletions

No files matched your search

@@ -1,90 +0,0 @@
"use client";
import { useTransition } from "react";
import { Button, Tooltip } from "@mantine/core";
import type { RouterOutputs } from "@homarr/api";
import { clientApi } from "@homarr/api/client";
import { showErrorNotification, showSuccessNotification } from "@homarr/notifications";
import { useI18n } from "@homarr/translation/client";
interface DisableUserButtonProps {
user: RouterOutputs["user"]["getById"];
isSelf?: boolean;
}
export const DisableUserButton = ({ user, isSelf = false }: DisableUserButtonProps) => {
const t = useI18n();
const [isPending, startTransition] = useTransition();
const changeDisabledMutation = clientApi.user.changeDisabled.useMutation();
const isDisabled = user.disabled;
const getSuccessMessage = () => {
if (isDisabled) {
return {
title: t("user.action.enable.success", { defaultValue: "User enabled" }),
message: t("user.action.enable.successDescription", { defaultValue: "User has been enabled" }),
};
}
return {
title: t("user.action.disable.success", { defaultValue: "User disabled" }),
message: t("user.action.disable.successDescription", { defaultValue: "User has been disabled" }),
};
};
const handleToggle = () => {
if (isSelf) return;
startTransition(async () => {
try {
await changeDisabledMutation.mutateAsync({
userId: user.id,
disabled: !isDisabled,
});
showSuccessNotification(getSuccessMessage());
} catch {
showErrorNotification({
title: t("common.notification.update.error"),
message: t("common.notification.update.error"),
});
}
});
};
const getTooltipLabel = () => {
if (isDisabled) {
return t("user.action.enable.description", { defaultValue: "Enable this user" });
}
return t("user.action.disable.description", { defaultValue: "Disable this user" });
};
const getButtonLabel = () => {
if (isDisabled) {
return t("user.action.enable.label", { defaultValue: "Enable user" });
}
return t("user.action.disable.label", { defaultValue: "Disable user" });
};
const getButtonColor = () => (isDisabled ? "green" : "yellow");
return (
<Tooltip
label={
isSelf
? t("user.action.disableSelf.disabled", { defaultValue: "Cannot disable your own account" })
: getTooltipLabel()
}
position="top"
>
<Button
onClick={handleToggle}
loading={isPending || changeDisabledMutation.isPending}
color={getButtonColor()}
variant="light"
disabled={isSelf}
>
{getButtonLabel()}
</Button>
</Tooltip>
);
};
@@ -11,7 +11,6 @@ import { catchTrpcNotFound } from "~/errors/trpc-catch-error";
import { createMetaTitle } from "~/metadata";
import { canAccessUserEditPage } from "../access";
import { DeleteUserButton } from "./_components/_delete-user-button";
import { DisableUserButton } from "./_components/_disable-user-button";
import { UserGeneralSettingsForm } from "./_components/_general-settings-form";
import { UserProfileAvatarForm } from "./_components/_profile-avatar-form";
import { ResetTours } from "./_components/_reset-tours";
@@ -62,19 +61,6 @@ export default async function EditUserPage(props: Props) {
const searchEngines = await api.searchEngine.getSelectable();
const isSelf = session?.user.id === user.id;
const isCredentialsUser = user.provider === "credentials";
const isDisabled = user.disabled;
const getDisableItemLabel = () => {
if (isDisabled) return t("user.action.enable.label");
return t("user.action.disable.label");
};
const getDisableItemDescription = () => {
if (isDisabled) {
return t("management.page.user.action.enable.description", { defaultValue: "Re-enable access for this user" });
}
return t("management.page.user.action.disable.description", { defaultValue: "Prevent this user from logging in" });
};
return (
<Stack>
@@ -110,13 +96,6 @@ export default async function EditUserPage(props: Props) {
)}
<DangerZoneRoot>
{!isSelf && (
<DangerZoneItem
label={getDisableItemLabel()}
description={getDisableItemDescription()}
action={<DisableUserButton user={user} isSelf={isSelf} />}
/>
)}
<DangerZoneItem
label={t("user.action.delete.label")}
description={t("user.action.delete.description")}
@@ -1,7 +1,7 @@
"use client";
import { useMemo } from "react";
import { Anchor, Badge, Group, Text, Tooltip } from "@mantine/core";
import { Anchor, Group, Text, Tooltip } from "@mantine/core";
import { IconCheck } from "@tabler/icons-react";
import type { MRT_ColumnDef } from "mantine-react-table";
import { MantineReactTable } from "mantine-react-table";
@@ -52,15 +52,6 @@ export const UserListComponent = ({ initialUserList }: UserListComponentProps) =
</Group>
),
},
{
accessorKey: "disabled",
header: t("user.field.status.label", { defaultValue: "Status" }),
size: 100,
Cell: ({ row }) => {
if (!row.original.disabled) return null;
return <Badge color="red">{t("user.field.status.disabled", { defaultValue: "Disabled" })}</Badge>;
},
},
],
[t],
);
-43
View File
@@ -232,7 +232,6 @@ export const userRouter = createTRPCRouter({
email: true,
emailVerified: true,
image: true,
disabled: true,
}),
),
)
@@ -253,7 +252,6 @@ export const userRouter = createTRPCRouter({
email: true,
emailVerified: true,
image: true,
disabled: true,
},
});
}),
@@ -343,7 +341,6 @@ export const userRouter = createTRPCRouter({
emailVerified: true,
image: true,
provider: true,
disabled: true,
homeBoardId: true,
mobileHomeBoardId: true,
firstDayOfWeek: true,
@@ -380,7 +377,6 @@ export const userRouter = createTRPCRouter({
emailVerified: true,
image: true,
provider: true,
disabled: true,
homeBoardId: true,
mobileHomeBoardId: true,
firstDayOfWeek: true,
@@ -781,45 +777,6 @@ export const userRouter = createTRPCRouter({
completedBoardTour: user?.completedBoardTour ?? false,
};
}),
changeDisabled: permissionRequiredProcedure
.requiresPermission("admin")
.input(
z.object({
userId: z.string(),
disabled: z.boolean(),
}),
)
.output(z.void())
.meta({
openapi: {
method: "PATCH",
path: "/api/users/disabled",
tags: ["users"],
protect: true,
},
})
.mutation(async ({ input, ctx }) => {
const dbUser = await ctx.db.query.users.findFirst({
columns: {
id: true,
},
where: eq(users.id, input.userId),
});
if (!dbUser) {
throw new TRPCError({
code: "NOT_FOUND",
message: "User not found",
});
}
await ctx.db
.update(users)
.set({
disabled: input.disabled,
})
.where(eq(users.id, input.userId));
}),
});
const createUserAsync = async (db: Database, input: Omit<z.infer<typeof userBaseCreateSchema>, "groupIds">) => {
@@ -23,11 +23,6 @@ export const authorizeWithBasicCredentialsAsync = async (
return null;
}
if (user.disabled) {
logger.warn("User is disabled", { userName: user.name });
return null;
}
logger.info("User is trying to log in. Checking password...", { userName: user.name });
const isValidPassword = await comparePasswordsAsync(credentials.password, user.password);
@@ -107,7 +107,6 @@ export const authorizeWithLdapCredentialsAsync = async (
email: true,
emailVerified: true,
provider: true,
disabled: true,
},
where: and(eq(users.email, mailResult.data), eq(users.provider, "ldap")),
});
@@ -131,11 +130,6 @@ export const authorizeWithLdapCredentialsAsync = async (
logger.info("User created successfully", { userName: credentials.name });
}
if (user.disabled) {
logger.warn("User is disabled", { userName: credentials.name });
throw new CredentialsSignin("User is disabled");
}
return {
id: user.id,
name: credentials.name,
@@ -1 +0,0 @@
ALTER TABLE `user` ADD `disabled` boolean DEFAULT false NOT NULL;
@@ -1 +0,0 @@
ALTER TABLE "user" ADD COLUMN "disabled" boolean DEFAULT false NOT NULL;
@@ -1 +0,0 @@
ALTER TABLE "user" ADD COLUMN "disabled" integer DEFAULT 0 NOT NULL;
-1
View File
@@ -72,7 +72,6 @@ export const users = mysqlTable("user", {
image: text(),
password: text(),
provider: varchar({ length: 64 }).$type<SupportedAuthProvider>().default("credentials").notNull(),
disabled: boolean().default(false).notNull(),
homeBoardId: varchar({ length: 64 }).references((): AnyMySqlColumn => boards.id, {
onDelete: "set null",
}),
-1
View File
@@ -71,7 +71,6 @@ export const users = pgTable("user", {
image: text(),
password: text(),
provider: varchar({ length: 64 }).$type<SupportedAuthProvider>().default("credentials").notNull(),
disabled: boolean().default(false).notNull(),
homeBoardId: varchar({ length: 64 }).references((): AnyPgColumn => boards.id, {
onDelete: "set null",
}),
-1
View File
@@ -54,7 +54,6 @@ export const users = sqliteTable("user", {
image: text(),
password: text(),
provider: text().$type<SupportedAuthProvider>().default("credentials").notNull(),
disabled: int({ mode: "boolean" }).default(false).notNull(),
homeBoardId: text().references((): AnySQLiteColumn => boards.id, {
onDelete: "set null",
}),
@@ -72,7 +72,14 @@ export const AppForm = ({
}
form.initialize(toFormValues(initialValues));
}, [initialValuesKey, form, initialValues]);
// `form` is a new object every render (Mantine useForm returns a fresh literal),
// so it must not be a dep here — it would re-run every render and, since
// form.initialize() always calls clearErrors() (new {} object) internally,
// trigger an infinite update loop. initialValuesKey (a primitive string)
// already captures the only case this effect exists for: re-initializing
// when initialValues actually changes (e.g. navigating between edit pages).
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [initialValuesKey]);
// Debounce the name value with 200ms delay
const [debouncedName] = useDebouncedValue(form.values.name, 200);