Skip to content

Commit 4eeb66a

Browse files
committed
fix(auth): drain response body on non-ok cross-tab fetch
Consumes the response body via r.body.cancel() when the cross-tab /user fetch returns a non-OK status, preventing connection pool drain on repeated events. Also strengthens the input-cleared test to reopen the form and verify the input signal was actually reset, not just that the DOM element was removed.
1 parent c4f6e6f commit 4eeb66a

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

src/app/stores/auth.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ if (typeof window !== "undefined") {
349349
fetch("https://api.github.com/user", {
350350
headers: { ...VALIDATE_HEADERS, Authorization: `Bearer ${newToken}` },
351351
})
352-
.then((r) => r.ok ? r.json() as Promise<GitHubUser> : null)
352+
.then((r) => { if (!r.ok) { void r.body?.cancel(); return null; } return r.json() as Promise<GitHubUser>; })
353353
.then((data) => {
354354
if (data && _token() === newToken && _crossTabFetchGen === gen) {
355355
setUser({ login: data.login, avatar_url: data.avatar_url, name: data.name });

tests/components/settings/SettingsPage.test.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,8 +566,13 @@ describe("SettingsPage — replace token", () => {
566566
const cancelBtn = screen.getByRole("button", { name: "Cancel" });
567567
await user.click(cancelBtn);
568568

569-
// Form is gone and input is cleared
569+
// Form is gone
570570
expect(screen.queryByRole("button", { name: "Replace token" })).toBeNull();
571+
572+
// Reopen and verify input was cleared
573+
await user.click(screen.getByRole("button", { name: "Replace" }));
574+
const reopenedInput = screen.getByLabelText(/new personal access token/i) as HTMLInputElement;
575+
expect(reopenedInput.value).toBe("");
571576
});
572577

573578
it("shows format error and does not fetch when token has wrong format", async () => {

0 commit comments

Comments
 (0)