Skip to content

πŸ™Œ OpenHands: AI-Driven Development

fix: clear stale urlSearchResults for non-matching HTTPS URLs in useUrlSearch (#16700)

Nicholas-Xiong49812ee20d5f
diff --git a/__tests__/components/features/home/use-url-search.test.tsx b/__tests__/components/features/home/use-url-search.test.tsx
index 70489f5d95..17de80a730 100644
--- a/__tests__/components/features/home/use-url-search.test.tsx
+++ b/__tests__/components/features/home/use-url-search.test.tsx
@@ -238,4 +238,44 @@ describe("useUrlSearch", () => {
});
});
});
+ it("should clear prior results when an HTTPS URL does not match repo pattern", async () => {
+ mockSearchGitRepositories.mockResolvedValue({
+ items: [
+ {
+ id: "1",
+ full_name: "owner/repo",
+ git_provider: "github",
+ is_public: true,
+ },
+ ],
+ next_page_id: null,
+ });
+
+ const { result, rerender } = renderHook(
+ ({ inputValue, provider }) => useUrlSearch(inputValue, provider),
+ {
+ initialProps: {
+ inputValue: "https://github.com/owner/repo",
+ provider: "github" as const,
+ },
+ },
+ );
+
+ await waitFor(() => {
+ expect(result.current.urlSearchResults).toHaveLength(1);
+ });
+
+ rerender({
+ inputValue: "https://example.com/",
+ provider: "github" as const,
+ });
+
+ await waitFor(() => {
+ expect(result.current.urlSearchResults).toEqual([]);
+ });
+
+ // Only the initial search for owner/repo should have triggered a call;
+ // the non-matching HTTPS URL must not issue a second request.
+ expect(mockSearchGitRepositories).toHaveBeenCalledTimes(1);
+ });
});
diff --git a/src/components/features/home/git-repo-dropdown/use-url-search.tsx b/src/components/features/home/git-repo-dropdown/use-url-search.tsx
index c6d8181fa7..d375cad6a7 100644
--- a/src/components/features/home/git-repo-dropdown/use-url-search.tsx
+++ b/src/components/features/home/git-repo-dropdown/use-url-search.tsx
@@ -38,6 +38,8 @@ export function useUrlSearch(
} finally {
setIsUrlSearchLoading(false);
}
+ } else {
+ setUrlSearchResults([]);
}
} else {
setUrlSearchResults([]);