@devries-cameron20 / t3code-1 / commits / 28d2262083
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(web): theme wallpaper stays in the live preview when connectivity returns (#38132)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Wout Stiens committed Nov 17, 2026 at 15:02 UTC 28d22620830182d552895ffe7a57ffe994823954
2 files changed +19 -1
apps/web/src/themeBackground.test.ts
+15
@@ -42,6 +42,7 @@ import {
42 CUSTOM_THEMES_STORAGE_KEY,
43 getThemeDefinition,
44 invalidateCustomThemes,
45 + THEME_PREVIEW_ID,
46 } from "./themePalette";
47
48 const BACKGROUND = "--theme-background-image";
@@ -129,6 +130,20 @@ describe("theme backgrounds", () => {
130 expect(t.fetchBackground).toHaveBeenCalledTimes(6);
131 });
132
133 + it("keeps the shown background under a draft preview when the browser comes back online", async () => {
134 + using t = setup();
135 + t.fetchBackground.mockImplementation(loaded);
136 + applyThemeBackground("nightfall");
137 + await vi.advanceTimersByTimeAsync(0);
138 + const shown = t.properties.get(BACKGROUND);
139 + expect(shown).toMatch(/^url\("blob:/);
140 +
141 + document.documentElement.dataset.themeId = THEME_PREVIEW_ID;
142 + t.browser.dispatchEvent(new Event("online"));
143 + await vi.advanceTimersByTimeAsync(0);
144 + expect(t.properties.get(BACKGROUND)).toBe(shown);
145 + });
146 +
147 it.each(["theme change", "disposal"])("stops retrying after %s", async (reason) => {
148 using t = setup();
149 applyThemeBackground("nightfall");
apps/web/src/themeBackground.ts
+4 -1
@@ -12,6 +12,8 @@ import { getCustomThemes } from "./themePalette";
12 const THEME_BACKGROUND_VARIABLE = "--theme-background-image";
13 const RETRY_DELAYS_MS = [1_000, 2_000, 4_000, 8_000];
14
15 +// The editor's draft preview replaces the root's theme id, so retries track this instead.
16 +let appliedThemeId: string | undefined;
17 let shownKey: string | null = null;
18 let loading: AbortController | null = null;
19 let objectUrl: string | null = null;
@@ -55,6 +57,7 @@ async function loadBackground(
57 */
58 export function applyThemeBackground(themeId: string | undefined): void {
59 if (typeof document === "undefined") return;
60 + appliedThemeId = themeId;
61 const environmentId = appAtomRegistry.get(themeEnvironmentIdAtom);
62 // A saved theme wins its id over a published one, so the published image is not its.
63 const revision =
@@ -110,7 +113,7 @@ export function applyThemeBackground(themeId: string | undefined): void {
113 * Coming back online retries a download that failed; a shown image is left alone.
114 */
115 export function startThemeBackground(): () => void {
113 - const reapply = () => applyThemeBackground(document.documentElement.dataset.themeId);
116 + const reapply = () => applyThemeBackground(appliedThemeId);
117 const unsubscribe = subscribeAtomChanges(themeServerEnvironmentThemesAtom, reapply);
118 window.addEventListener("online", reapply);
119 return () => {