Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.
Python aicode-complexitycode-healthcode-intelligencecode-qualitydead-codedeveloper-toolsdocumentationgit-analyticsmcpopen-sourcepythonrefactoringstatic-analysistechnical-debt
fix(chat): keep the URL bare on a new conversation (#3576)
Muhammad Haris Awan3ccdc95edcb6
diff --git a/packages/web/src/components/chat/chat-interface.test.tsx b/packages/web/src/components/chat/chat-interface.test.tsxindex 974d676c2..0e6bb1143 100644--- a/packages/web/src/components/chat/chat-interface.test.tsx+++ b/packages/web/src/components/chat/chat-interface.test.tsx@@ -78,6 +78,23 @@ describe("chat route conversation lifecycle", () => {expect(mocks.loadConversation).not.toHaveBeenCalled();});+ it("leaves the URL bare when a new conversation is requested over an open one", async () => {+ // #3084: opening "New conversation" pushes the bare /chat URL while the+ // provider still holds the id being closed. `reset()` has not applied in+ // that same commit, so the URL-sync effect used to read the stale id and+ // write it straight back, re-opening the conversation just closed.+ mocks.conversation = "a";+ mocks.activeConversation = "a";+ const view = render(<ChatInterface repoId="r1" />);+ await waitFor(() => expect(mocks.shellProps).not.toBeNull());+ expect(mocks.reset).not.toHaveBeenCalled();++ mocks.conversation = null;+ view.rerender(<ChatInterface repoId="r1" />);+ await waitFor(() => expect(mocks.reset).toHaveBeenCalledOnce());+ expect(mocks.replace).not.toHaveBeenCalledWith("/repos/r1/chat?conversation=a");+ });+it("passes artifact deep links through and preserves the conversation when navigating artifacts", async () => {mocks.conversation = "c42";mocks.artifact = "a1";diff --git a/packages/web/src/components/chat/chat-interface.tsx b/packages/web/src/components/chat/chat-interface.tsxindex a9060abeb..b2e023b92 100644--- a/packages/web/src/components/chat/chat-interface.tsx+++ b/packages/web/src/components/chat/chat-interface.tsx@@ -71,7 +71,10 @@ export function ChatInterface({// conversation URL restores history, which keeps returning users from being// dropped at the bottom of an old answer they did not choose to reopen.const lifecycleRef = useRef("");- const awaitingFreshIdRef = useRef(false);+ // The id the fresh workspace was requested over, or true when there was none.+ // `reset()` has not applied when the sync effect below runs in the same+ // commit, so it would otherwise read the id being closed and write it back.+ const awaitingFreshIdRef = useRef<string | boolean>(false);useEffect(() => {const identity = `${repoId}:${urlConversationId ?? "new"}:${initialQuestion ?? ""}`;if (lifecycleRef.current === identity) return;@@ -83,7 +86,7 @@ export function ChatInterface({}return;}- awaitingFreshIdRef.current = true;+ awaitingFreshIdRef.current = conversationId || true;reset();if (initialQuestion) void sendMessage(initialQuestion, {context: pageContext,@@ -94,6 +97,8 @@ export function ChatInterface({useEffect(() => {if (!awaitingFreshIdRef.current || !conversationId) return;+ // Never re-sync the id the fresh workspace was requested over.+ if (awaitingFreshIdRef.current === conversationId) return;awaitingFreshIdRef.current = false;const next = new URLSearchParams(searchParams.toString());next.delete("q");