From c3cca50f27770f9bcc3cb48eaf773ac321fd160b Mon Sep 17 00:00:00 2001 From: Naiyuan Qing <145280634+NevilleQingNY@users.noreply.github.com> Date: Thu, 2 Apr 2026 18:51:14 +0800 Subject: [PATCH] fix(inbox): parse issue query param on initial page load Use useState for selectedKey instead of deriving directly from useSearchParams(), so the issue ID from ?issue= is reliably captured on mount. window.history.replaceState() doesn't always sync back to useSearchParams() in Next.js, causing the detail panel to show empty when entering via a shared inbox link. Co-Authored-By: Claude Opus 4.6 (1M context) --- apps/web/app/(dashboard)/inbox/page.tsx | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/apps/web/app/(dashboard)/inbox/page.tsx b/apps/web/app/(dashboard)/inbox/page.tsx index 65b3191b..d2e8112b 100644 --- a/apps/web/app/(dashboard)/inbox/page.tsx +++ b/apps/web/app/(dashboard)/inbox/page.tsx @@ -1,5 +1,6 @@ "use client"; +import { useState, useEffect, useCallback } from "react"; import { useSearchParams } from "next/navigation"; import { useDefaultLayout } from "react-resizable-panels"; import { useInboxStore } from "@/features/inbox"; @@ -219,11 +220,20 @@ function InboxListItem({ export default function InboxPage() { const searchParams = useSearchParams(); - const selectedKey = searchParams.get("issue") ?? ""; - const setSelectedKey = (key: string) => { + const urlIssue = searchParams.get("issue") ?? ""; + + const [selectedKey, setSelectedKeyState] = useState(() => urlIssue); + + // Sync from URL when searchParams change (e.g. Next.js navigation) + useEffect(() => { + setSelectedKeyState(urlIssue); + }, [urlIssue]); + + const setSelectedKey = useCallback((key: string) => { + setSelectedKeyState(key); const url = key ? `/inbox?issue=${key}` : "/inbox"; window.history.replaceState(null, "", url); - }; + }, []); const items = useInboxStore((s) => s.dedupedItems()); const loading = useInboxStore((s) => s.loading);