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

Co-authored-by: vasco <vasco.schiavo@protonmail.com>
This commit is contained in:
Nicholas-Xiong
2026-08-19 05:38:31 +00:00
committed by GitHub
co-authored by vasco
parent 48038afbcc
commit 49812ee20d
2 changed files with 42 additions and 0 deletions
@@ -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);
});
});
@@ -38,6 +38,8 @@ export function useUrlSearch(
} finally {
setIsUrlSearchLoading(false);
}
} else {
setUrlSearchResults([]);
}
} else {
setUrlSearchResults([]);