Repository navigation
Closed
Labels
vouch:trustedAuthor is trusted by repo permissions or the VOUCHED list.
Description
Before submitting
- I searched existing issues and did not find a duplicate.
- I included enough detail to reproduce or investigate the problem.
Area
apps/web
Steps to reproduce
- Open Appearance settings with a published theme that includes a background image available.
- Temporarily interrupt network access while applying that theme so its background download fails.
- Restore network access while leaving the theme selected and the app open.
Expected behavior
The selected theme downloads and displays its wallpaper after network access recovers.
Actual behavior
The wallpaper stays absent until the theme is reapplied, the app is reloaded, or another theme update arrives.
Impact
Minor bug or occasional failure. Users whose wallpaper download fails temporarily can remain without it for the rest of their session even after network access recovers.
Version or commit
main at 6dd092315e. The cause is at apps/web/src/themeBackground.ts:75.
Environment
Linux x64, the repository's own tests.
Logs or stack traces
AssertionError: expected '' to matchAutomated repro
Fails in 2 of 2 runs on main: apply the patch with git apply, then run the command.
diff --git a/apps/web/src/themeBackground.test.ts b/apps/web/src/themeBackground.test.ts
new file mode 100644
index 0000000000..08a3a57530
--- /dev/null
+++ b/apps/web/src/themeBackground.test.ts
@@ -0,0 +1,82 @@
+import { EnvironmentId } from "@t3tools/contracts";
+import { describe, expect, it, vi } from "vite-plus/test";
+
+const query = vi.hoisted(() => vi.fn());
+vi.mock(
+ import("@t3tools/client-runtime/state/runtime"),
+ () =>
+ ({
+ executeAtomQuery: query,
+ }) as never,
+);
+vi.mock(import("./state/primaryEnvironment"), async () => {
+ const { Atom } = await import("effect/reactivity");
+ return { themeEnvironmentIdAtom: Atom.make(EnvironmentId.make("host")) } as never;
+});
+vi.mock(import("./state/server"), async () => {
+ const { Atom } = await import("effect/reactivity");
+ return {
+ themeServerEnvironmentThemesAtom: Atom.make([{ id: "nightfall", background: "revision-1" }]),
+ } as never;
+});
+vi.mock(import("./state/session"), async () => {
+ const { Atom } = await import("effect/reactivity");
+ return {
+ environmentSession: {
+ preparedConnectionValueAtom: Atom.family(() =>
+ Atom.make({ _tag: "Some", value: { httpBaseUrl: "https://example.com/" } }),
+ ),
+ },
+ } as never;
+});
+vi.mock(
+ import("./state/assets"),
+ () =>
+ ({
+ assetEnvironment: { createUrl: vi.fn() },
+ }) as never,
+);
+
+import { applyThemeBackground, startThemeBackground } from "./themeBackground";
+
+describe("theme backgrounds", () => {
+ it("restores the selected background after its initial fetch fails and the network recovers", async () => {
+ vi.useFakeTimers();
+ const properties = new Map<string, string>();
+ const browser = new EventTarget();
+ vi.stubGlobal("window", browser);
+ vi.stubGlobal("document", {
+ documentElement: {
+ dataset: { themeId: "nightfall" },
+ style: {
+ setProperty: (name: string, value: string) => properties.set(name, value),
+ removeProperty: (name: string) => properties.delete(name),
+ },
+ },
+ });
+ query.mockResolvedValue({ _tag: "Success", value: { relativeUrl: "/background.png" } });
+ const image = new Blob(["image"], { type: "image/png" });
+ vi.stubGlobal(
+ "fetch",
+ vi
+ .fn()
+ .mockRejectedValueOnce(new TypeError("Failed to fetch"))
+ .mockImplementation(async () => new Response(image)),
+ );
+ const stop = startThemeBackground();
+ try {
+ applyThemeBackground("nightfall");
+ await vi.advanceTimersByTimeAsync(0);
+ expect(properties.has("--theme-background-image")).toBe(false);
+
+ browser.dispatchEvent(new Event("online"));
+ await vi.advanceTimersByTimeAsync(30_000);
+ expect(properties.get("--theme-background-image") ?? "").toMatch(/^url\("blob:/);
+ } finally {
+ stop();
+ applyThemeBackground(undefined);
+ vi.unstubAllGlobals();
+ vi.useRealTimers();
+ }
+ });
+});cd apps/web && pnpm exec vp test run src/themeBackground.test.tsWorkaround
No response
Metadata
Metadata
Assignees
Labels
vouch:trustedAuthor is trusted by repo permissions or the VOUCHED list.
Activity