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): published background no longer shows under a saved theme with the same id (#37981)
Julius Marminge committed
Nov 16, 2026 at 23:43 UTC
49c3ab86323444c3464f1404ace52017ccd7f83b
2 files changed
+33
-3
apps/web/src/themeBackground.test.ts
+30
-2
@@ -38,17 +38,25 @@ vi.mock(
38
);
39
40
import { applyThemeBackground, startThemeBackground } from "./themeBackground";
41
+import {
42
+ CUSTOM_THEMES_STORAGE_KEY,
43
+ getThemeDefinition,
44
+ invalidateCustomThemes,
45
+} from "./themePalette";
46
47
const BACKGROUND = "--theme-background-image";
48
const image = new Blob(["image"], { type: "image/png" });
49
const offline = () => Promise.reject(new TypeError("Failed to fetch"));
50
const loaded = async () => ({ ok: true, blob: async () => image });
51
47
-function setup() {
52
+function setup(storage: Record<string, string> = {}) {
53
vi.useFakeTimers();
54
const properties = new Map<string, string>();
50
- const browser = new EventTarget();
55
+ const browser = Object.assign(new EventTarget(), {
56
+ localStorage: { getItem: (key: string) => storage[key] ?? null },
57
+ });
58
vi.stubGlobal("window", browser);
59
+ invalidateCustomThemes();
60
vi.stubGlobal("document", {
61
documentElement: {
62
dataset: { themeId: "nightfall" },
@@ -71,6 +79,7 @@ function setup() {
79
stop();
80
applyThemeBackground(undefined);
81
vi.unstubAllGlobals();
82
+ invalidateCustomThemes();
83
vi.useRealTimers();
84
},
85
};
@@ -129,4 +138,23 @@ describe("theme backgrounds", () => {
138
await vi.advanceTimersByTimeAsync(30_000);
139
expect(t.fetchBackground).toHaveBeenCalledTimes(1);
140
});
141
+
142
+ it("shows no published background when a saved theme shares its id", async () => {
143
+ using t = setup({
144
+ [CUSTOM_THEMES_STORAGE_KEY]: JSON.stringify([
145
+ {
146
+ id: "nightfall",
147
+ label: "Nightfall",
148
+ appearance: "dark",
149
+ colors: { canvas: "#162327", accent: "#cc3344" },
150
+ },
151
+ ]),
152
+ });
153
+ t.fetchBackground.mockImplementation(loaded);
154
+ expect(getThemeDefinition("nightfall")?.colors.accent).toBeDefined();
155
+ applyThemeBackground("nightfall");
156
+ await vi.advanceTimersByTimeAsync(0);
157
+ expect(t.fetchBackground).not.toHaveBeenCalled();
158
+ expect(t.properties.has(BACKGROUND)).toBe(false);
159
+ });
160
});
apps/web/src/themeBackground.ts
+3
-1
@@ -7,6 +7,7 @@ import { assetEnvironment } from "./state/assets";
7
import { themeEnvironmentIdAtom } from "./state/primaryEnvironment";
8
import { themeServerEnvironmentThemesAtom } from "./state/server";
9
import { environmentSession } from "./state/session";
10
+import { getCustomThemes } from "./themePalette";
11
12
const THEME_BACKGROUND_VARIABLE = "--theme-background-image";
13
const RETRY_DELAYS_MS = [1_000, 2_000, 4_000, 8_000];
@@ -55,8 +56,9 @@ async function loadBackground(
56
export function applyThemeBackground(themeId: string | undefined): void {
57
if (typeof document === "undefined") return;
58
const environmentId = appAtomRegistry.get(themeEnvironmentIdAtom);
59
+ // A saved theme wins its id over a published one, so the published image is not its.
60
const revision =
59
- themeId === undefined
61
+ themeId === undefined || getCustomThemes().some((theme) => theme.id === themeId)
62
? undefined
63
: appAtomRegistry.get(themeServerEnvironmentThemesAtom)?.find((theme) => theme.id === themeId)
64
?.background;