fix(chat-panel): update path handling with usePathname for URL management

When `basePath` is set, using `window.location.pathname` causes the `basePath` to be duplicated.
This commit is contained in:
shibamudi
2026-01-30 00:02:25 +09:00
committed by dayuan.jiang
parent 31fffcc52d
commit 0a79536002
+4 -3
View File
@@ -9,7 +9,7 @@ import {
Settings, Settings,
} from "lucide-react" } from "lucide-react"
import Image from "next/image" import Image from "next/image"
import { useRouter, useSearchParams } from "next/navigation" import { usePathname, useRouter, useSearchParams } from "next/navigation"
import type React from "react" import type React from "react"
import { import {
useCallback, useCallback,
@@ -131,6 +131,7 @@ export default function ChatPanel({
const dict = useDictionary() const dict = useDictionary()
const router = useRouter() const router = useRouter()
const pathname = usePathname()
const searchParams = useSearchParams() const searchParams = useSearchParams()
const urlSessionId = searchParams.get("session") const urlSessionId = searchParams.get("session")
@@ -901,7 +902,7 @@ export default function ChatPanel({
if (result.wasCurrentSession) { if (result.wasCurrentSession) {
// Deleted current session - clear UI and URL // Deleted current session - clear UI and URL
syncUIWithSession(null) syncUIWithSession(null)
router.replace(window.location.pathname, { scroll: false }) router.replace(pathname, { scroll: false })
} }
}, },
[sessionManager, syncUIWithSession, router], [sessionManager, syncUIWithSession, router],
@@ -937,7 +938,7 @@ export default function ChatPanel({
toast.success(dict.dialogs.clearSuccess) toast.success(dict.dialogs.clearSuccess)
// Clear URL param to show blank state // Clear URL param to show blank state
router.replace(window.location.pathname, { scroll: false }) router.replace(pathname, { scroll: false })
// After starting a fresh chat, move focus back to the chat input // After starting a fresh chat, move focus back to the chat input
setShouldFocusInput(true) setShouldFocusInput(true)