Skip to content

[Bug]: A rejected theme file can bring back the file it replaced #40964

Closed

Description

@StiensWout

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

  1. Open Settings → Appearance.
  2. Click Add theme.
  3. Drop a theme JSON file into the dialog.
  4. While the file is still being read, drop a JSON file larger than 256 KB into the same dialog.
  5. Wait for the first file to finish reading.

Expected behavior

The size error stays visible and the dialog waits for another file or pasted JSON.

Actual behavior

The size error disappears, the first file becomes the draft, and Add theme installs that earlier file.

dialog after earlier theme read finishes

failure

Impact

Minor bug or occasional failure. Users who drop an oversized replacement while a previous file is still loading can accidentally add the previous theme.

Version or commit

main at 7ddc81d639. The cause is at apps/web/src/components/settings/ThemeImportDialog.tsx:245.

Environment

Linux x64 boat.dev default machine, a fresh checkout.

Logs or stack traces

Add theme
Automated repro

Fails in 2 of 2 runs on main: apply the patch with git apply, then run the command.

diff --git a/scripts/scenarios/rejected-theme-file-supersedes-earlier-read.e2e.ts b/scripts/scenarios/rejected-theme-file-supersedes-earlier-read.e2e.ts
new file mode 100644
index 0000000000..49186eaa44
--- /dev/null
+++ b/scripts/scenarios/rejected-theme-file-supersedes-earlier-read.e2e.ts
@@ -0,0 +1,64 @@
+/// <reference lib="dom" />
+import { expect } from "e2e";
+
+import { test, WEB } from "./t3.ts";
+
+declare global {
+  interface Window {
+    releaseOldThemeRead: () => void;
+  }
+}
+
+test(
+  "An earlier theme file cannot become the draft after its replacement is rejected",
+  WEB,
+  async ({ t3, app, browser, screen }) => {
+    await t3.project("demo");
+    await t3.open("/settings/appearance");
+    await screen.getByRole("button", "Add theme", { exact: true }).tap();
+    const dialog = screen.getByRole("dialog", "Add a theme");
+
+    await browser.evaluate(() => {
+      const target = document.querySelector('input[type="file"]')?.parentElement;
+      if (!target) throw new Error("No theme file drop target");
+
+      const gate = Promise.withResolvers<void>();
+      const theme = JSON.stringify({
+        version: 1,
+        name: "Earlier theme",
+        appearance: "dark",
+        colors: { accent: "#734ee4" },
+      });
+      const first = new File([theme], "earlier.json", { type: "application/json" });
+      const text = File.prototype.text;
+      File.prototype.text = function () {
+        if (this.name === first.name) return gate.promise.then(() => theme);
+        return text.call(this);
+      };
+      window.releaseOldThemeRead = gate.resolve;
+
+      const drop = (file: File) => {
+        const files = new DataTransfer();
+        files.items.add(file);
+        target.dispatchEvent(
+          new DragEvent("drop", { dataTransfer: files, bubbles: true, cancelable: true }),
+        );
+      };
+      drop(first);
+      drop(new File([" ".repeat(300_000)], "replacement.json", { type: "application/json" }));
+      return null;
+    });
+
+    await dialog.getByText(/That file is/).waitFor();
+    await browser.evaluate(async () => {
+      window.releaseOldThemeRead();
+      // Let the earlier file response and its React update reach the dialog.
+      await new Promise<void>((resolve) =>
+        requestAnimationFrame(() => requestAnimationFrame(() => resolve())),
+      );
+      return null;
+    });
+    await app.screenshot("dialog-after-earlier-theme-read-finishes");
+    await expect(dialog.getByRole("button", "Add theme", { exact: true })).toBeDisabled();
+  },
+);
pnpm scenarios:prove scripts/scenarios/rejected-theme-file-supersedes-earlier-read.e2e.ts --base main

Workaround

No response

Activity

  1. added
    vouch:trusted
    on Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    vouch:trusted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions