Skip to content
Open
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
9 changes: 6 additions & 3 deletions apps/web/src/components/AppSidebarLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, type ReactNode } from "react";
import { useNavigate } from "@tanstack/react-router";
import { useEffect, useRef, type ReactNode } from "react";
import { useLocation, useNavigate } from "@tanstack/react-router";

import ThreadSidebar from "./Sidebar";
import { Sidebar, SidebarProvider, SidebarRail } from "./ui/sidebar";
Expand All @@ -13,6 +13,9 @@ const THREAD_SIDEBAR_MIN_WIDTH = 13 * 16;
const THREAD_MAIN_CONTENT_MIN_WIDTH = 40 * 16;
export function AppSidebarLayout({ children }: { children: ReactNode }) {
const navigate = useNavigate();
const pathname = useLocation({ select: (location) => location.pathname });
const pathnameRef = useRef(pathname);
pathnameRef.current = pathname;

useEffect(() => {
const onWindowKeyDown = (event: KeyboardEvent) => {
Expand Down Expand Up @@ -44,7 +47,7 @@ export function AppSidebarLayout({ children }: { children: ReactNode }) {

const unsubscribe = onMenuAction((action) => {
if (action === "open-settings") {
void navigate({ to: "/settings" });
void navigate({ to: "/settings", replace: pathnameRef.current.startsWith("/settings") });
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Use a boundary-safe settings route check before replace.

Line 50 uses startsWith("/settings"), which also matches paths like /settings-foo. That can replace history unexpectedly outside the settings section.

Proposed fix
-        void navigate({ to: "/settings", replace: pathnameRef.current.startsWith("/settings") });
+        const isInSettings =
+          pathnameRef.current === "/settings" ||
+          pathnameRef.current.startsWith("/settings/");
+        void navigate({ to: "/settings", replace: isInSettings });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
void navigate({ to: "/settings", replace: pathnameRef.current.startsWith("/settings") });
const isInSettings =
pathnameRef.current === "/settings" ||
pathnameRef.current.startsWith("/settings/");
void navigate({ to: "/settings", replace: isInSettings });
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/web/src/components/AppSidebarLayout.tsx` at line 50, The replace
decision uses pathnameRef.current.startsWith("/settings") which incorrectly
matches paths like "/settings-foo"; update the condition used when calling
navigate({ to: "/settings", replace: ... }) to perform a boundary-safe check
(e.g. test that pathnameRef.current is exactly "/settings" or matches the
"/settings" segment boundary such as using a regex like /^\/settings(\/|$)/ or
checking startsWith("/settings/")) so only true settings routes trigger replace;
locate the call in AppSidebarLayout where navigate and pathnameRef.current are
used and replace the startsWith check with the boundary-safe check.

}
});

Expand Down
Loading