Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 28 additions & 22 deletions apps/web/src/routes/settings.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { RotateCcwIcon } from "lucide-react";
import { Outlet, createFileRoute, redirect } from "@tanstack/react-router";
import { Outlet, createFileRoute, redirect, useLocation } from "@tanstack/react-router";
import { useEffect, useState } from "react";

import { useSettingsRestore } from "../components/settings/SettingsPanels";
Expand All @@ -8,10 +8,12 @@ import { SidebarInset, SidebarTrigger } from "../components/ui/sidebar";
import { isElectron } from "../env";

function SettingsContentLayout() {
const location = useLocation();
const [restoreSignal, setRestoreSignal] = useState(0);
const { changedSettingLabels, restoreDefaults } = useSettingsRestore(() =>
setRestoreSignal((value) => value + 1),
);
const showRestoreDefaults = location.pathname === "/settings/general";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hook runs unnecessary computation on non-general settings pages

Low Severity

useSettingsRestore is called unconditionally on every settings route (general, archived, connections), but its return values (changedSettingLabels, restoreDefaults) are only consumed when showRestoreDefaults is true (i.e., on /settings/general). The hook internally subscribes to useTheme(), useSettings(), and useUpdateSettings(), computes dirty state across multiple settings, and builds memoized arrays and callbacks—all wasted work on the archived and connections pages. Moving the hook call behind the showRestoreDefaults condition (or into a child component rendered only on general) would avoid this unnecessary computation and context subscriptions.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit e10cab0. Configure here.


useEffect(() => {
const onKeyDown = (event: KeyboardEvent) => {
Expand All @@ -33,9 +35,32 @@ function SettingsContentLayout() {
<div className="flex min-h-0 min-w-0 flex-1 flex-col bg-background text-foreground">
{!isElectron && (
<header className="border-b border-border px-3 py-2 sm:px-5">
<div className="flex items-center gap-2">
<div className="flex min-h-7 items-center gap-2 sm:min-h-6">
<SidebarTrigger className="size-7 shrink-0 md:hidden" />
<span className="text-sm font-medium text-foreground">Settings</span>
{showRestoreDefaults ? (
<div className="ms-auto flex items-center gap-2">
<Button
size="xs"
variant="outline"
disabled={changedSettingLabels.length === 0}
onClick={() => void restoreDefaults()}
>
<RotateCcwIcon className="size-3.5" />
Restore defaults
</Button>
</div>
) : null}
</div>
</header>
)}

{isElectron && (
<div className="drag-region flex h-[52px] shrink-0 items-center border-b border-border px-5 wco:h-[env(titlebar-area-height)] wco:pr-[calc(100vw-env(titlebar-area-width)-env(titlebar-area-x)+1em)]">
<span className="text-xs font-medium tracking-wide text-muted-foreground/70">
Settings
</span>
{showRestoreDefaults ? (
<div className="ms-auto flex items-center gap-2">
<Button
size="xs"
Expand All @@ -47,26 +72,7 @@ function SettingsContentLayout() {
Restore defaults
</Button>
</div>
</div>
</header>
)}

{isElectron && (
<div className="drag-region flex h-[52px] shrink-0 items-center border-b border-border px-5 wco:h-[env(titlebar-area-height)] wco:pr-[calc(100vw-env(titlebar-area-width)-env(titlebar-area-x)+1em)]">
<span className="text-xs font-medium tracking-wide text-muted-foreground/70">
Settings
</span>
<div className="ms-auto flex items-center gap-2">
<Button
size="xs"
variant="outline"
disabled={changedSettingLabels.length === 0}
onClick={() => void restoreDefaults()}
>
<RotateCcwIcon className="size-3.5" />
Restore defaults
</Button>
</div>
) : null}
</div>
)}

Expand Down
Loading