Skip to content
TypeScript

fix(web): skip star prompt when the server check is unavailable (#28364)

t3-code-bot[bot]5806afff6766
diff --git a/apps/web/src/components/GitHubStarPrompt.test.ts b/apps/web/src/components/GitHubStarPrompt.test.ts
index 34f763646d6..9dbe023b2d5 100644
--- a/apps/web/src/components/GitHubStarPrompt.test.ts
+++ b/apps/web/src/components/GitHubStarPrompt.test.ts
@@ -5,7 +5,7 @@ import type { toastManager } from "./ui/toast";
const { add, starred } = vi.hoisted(() => ({
add: vi.fn<typeof toastManager.add>(),
- starred: { value: false, duringCheck: () => {} },
+ starred: { value: false, failed: false, duringCheck: () => {} },
}));
vi.mock("./ui/toast", () => ({ toastManager: { add, close: vi.fn() } }));
vi.mock("../rpc/atomRegistry", () => ({ appAtomRegistry: {} }));
@@ -13,7 +13,7 @@ vi.mock("../state/sourceControl", () => ({ sourceControlEnvironment: { checkStar
vi.mock("@t3tools/client-runtime/state/runtime", () => ({
runAtomCommand: async () => {
starred.duringCheck();
- return { _tag: "Success", value: starred.value };
+ return starred.failed ? { _tag: "Failure" } : { _tag: "Success", value: starred.value };
},
}));
@@ -22,6 +22,7 @@ const environmentId = EnvironmentId.make("environment-1");
function setup({ sent = 0, writable = true, alreadyStarred = false } = {}) {
add.mockReset();
starred.value = alreadyStarred;
+ starred.failed = false;
starred.duringCheck = () => {};
const store = new Map([["t3code:github-star-prompt:sent", String(sent)]]);
vi.stubGlobal("window", {
@@ -81,6 +82,18 @@ describe("recordPromptSent", () => {
vi.unstubAllGlobals();
});
+ it("skips an unavailable server check without permanently dismissing", async () => {
+ const store = setup({ sent: 5 });
+ starred.failed = true;
+ await (await startSession()).send();
+ expect(add).not.toHaveBeenCalled();
+ expect(store.has("t3code:github-star-prompt:dismissed")).toBe(false);
+ starred.failed = false;
+ await (await startSession()).send();
+ expect(add).toHaveBeenCalledOnce();
+ vi.unstubAllGlobals();
+ });
+
it("never asks when another tab dismisses it during the star check", async () => {
const store = setup({ sent: 5 });
starred.duringCheck = () => store.set("t3code:github-star-prompt:dismissed", "true");
diff --git a/apps/web/src/components/GitHubStarPrompt.tsx b/apps/web/src/components/GitHubStarPrompt.tsx
index d157d72960d..db8ddb4de20 100644
--- a/apps/web/src/components/GitHubStarPrompt.tsx
+++ b/apps/web/src/components/GitHubStarPrompt.tsx
@@ -64,7 +64,7 @@ async function alreadyStarred(environmentId: EnvironmentId) {
},
{ label: "check GitHub star", reportFailure: false, reportDefect: false },
);
- return result._tag === "Success" && result.value;
+ return result._tag === "Success" ? result.value : undefined;
}
/**
@@ -83,7 +83,9 @@ export async function recordPromptSent(environmentId: EnvironmentId): Promise<vo
return;
}
shownThisSession = true;
- if (await alreadyStarred(environmentId)) return dismiss();
+ const starred = await alreadyStarred(environmentId);
+ if (starred === undefined) return;
+ if (starred) return dismiss();
try {
// Another tab can dismiss while the check runs.
if (getLocalStorageItem(DISMISSED_KEY, Schema.Boolean)) return;