The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 08:30 UTC
fix(web): leaving Appearance cancels a pending theme install (#38021)
Co-authored-by: Grok 4.7 <noreply@x.ai> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Wout Stiens committed
Nov 17, 2026 at 10:27 UTC
d051d9822fcb96f939db109988df8635326d6554
3 files changed
+51
-4
apps/web/src/components/settings/ThemeImportDialog.browser.test.tsx
+35
-2
@@ -2,7 +2,7 @@ import { StrictMode } from "react";
2
import { describe, expect, it, vi } from "vite-plus/test";
3
import { page, userEvent } from "vite-plus/test/browser";
4
5
-import { render } from "../../../test/render";
5
+import { act, render } from "../../../test/render";
6
import {
7
CUSTOM_THEMES_STORAGE_KEY,
8
getCustomThemes,
@@ -12,7 +12,7 @@ import {
12
themeColorToHex,
13
THEME_FILE_VERSION,
14
} from "../../themePalette";
15
-import type { OpenVsxThemeExtension } from "../../openVsxThemes";
15
+import { importOpenVsxThemeExtension, type OpenVsxThemeExtension } from "../../openVsxThemes";
16
import { ThemeImportDialog } from "./ThemeImportDialog";
17
18
const searchOpenVsxThemes = vi.hoisted(() => vi.fn());
@@ -222,3 +222,36 @@ describe("ThemeImportDialog JSONC imports", () => {
222
]);
223
});
224
});
225
+
226
+it("does not install a pending community theme after leaving Appearance", async () => {
227
+ using _themes = isolateThemes();
228
+ searchOpenVsxThemes.mockReset();
229
+ searchOpenVsxThemes.mockResolvedValue([extension]);
230
+ const download = Promise.withResolvers<ReturnType<typeof parseThemeFile>[]>();
231
+ vi.mocked(importOpenVsxThemeExtension).mockReset();
232
+ vi.mocked(importOpenVsxThemeExtension).mockReturnValue(download.promise);
233
+ await using screen = await render(
234
+ <ThemeImportDialog
235
+ open
236
+ onOpenChange={() => {}}
237
+ onImported={() => true}
238
+ onImportedMany={() => {}}
239
+ />,
240
+ );
241
+ await userEvent.fill(page.getByLabelText("Search Open VSX themes"), "night");
242
+ await page.getByRole("button", { name: "Install Nightfall" }).click();
243
+ await screen.unmount();
244
+ await act(async () => {
245
+ download.resolve([
246
+ {
247
+ ...parseThemeFile(theme("Nightfall")),
248
+ collection: { id: extension.collectionId, label: extension.name },
249
+ },
250
+ ]);
251
+ await download.promise;
252
+ });
253
+ expect(
254
+ getCustomThemes(),
255
+ "expect leaving Appearance to cancel its pending theme installation",
256
+ ).toEqual([]);
257
+});
apps/web/src/components/settings/ThemeImportDialog.tsx
+15
-1
@@ -1,7 +1,7 @@
1
import { DownloadIcon, PlusIcon } from "lucide-react";
2
import type { ChangeEvent, DragEvent, UIEvent } from "react";
3
import { settlePromise } from "@t3tools/client-runtime/state/runtime";
4
-import { useRef, useState } from "react";
4
+import { useEffect, useRef, useState } from "react";
5
import { formatBytes } from "../../lib/formatBytes";
6
import { cn } from "../../lib/utils";
7
import {
@@ -165,6 +165,20 @@ export function ThemeImportDialog({
165
session.controller.abort();
166
onOpenChange(false);
167
};
168
+ // Leaving the page ends the session as closing does. The abort waits a microtask
169
+ // so StrictMode's replayed cleanup, undone by its replayed setup, keeps it alive.
170
+ const { controller } = session;
171
+ const mountedController = useRef<AbortController | null>(null);
172
+ // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- unmounting must abort in-flight Open VSX installs
173
+ useEffect(() => {
174
+ mountedController.current = controller;
175
+ return () => {
176
+ mountedController.current = null;
177
+ queueMicrotask(() => {
178
+ if (mountedController.current !== controller) controller.abort();
179
+ });
180
+ };
181
+ }, [controller]);
182
183
return (
184
<Dialog
apps/web/tsconfig.json
+1
-1
@@ -7,7 +7,7 @@
7
"erasableSyntaxOnly": false,
8
"verbatimModuleSyntax": false,
9
"jsx": "react-jsx",
10
- "lib": ["ES2023", "ESNext.Disposable", "DOM", "DOM.Iterable"],
10
+ "lib": ["ES2023", "ES2024.Promise", "ESNext.Disposable", "DOM", "DOM.Iterable"],
11
"paths": {
12
"~/*": ["./src/*"]
13
},