@devries-cameron20 / t3code-1 / commits / 58f609f7cc
Fork 0

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

fix(web): theme import no longer says a file just under 1 MB is "1024 KB" (#30330)

Co-authored-by: Julius Marminge <julius0216@outlook.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

spoukyii committed Nov 14, 2026 at 21:17 UTC 58f609f7cceea4a0b628fe824ec86cdd855d3977
2 files changed +25 -7
apps/web/src/components/settings/ThemeImportDialog.browser.test.tsx
+23
@@ -128,6 +128,29 @@ function isolateThemes() {
128 };
129 }
130
131 +it("sizes an oversized theme file just under 1 MB as 1.00 MB", async () => {
132 + using _themes = isolateThemes();
133 + await using _screen = await render(
134 + <ThemeImportDialog
135 + open
136 + onOpenChange={() => {}}
137 + onImported={() => true}
138 + onImportedMany={() => {}}
139 + />,
140 + );
141 + const input = document.querySelector<HTMLInputElement>('input[type="file"]')!;
142 + await userEvent.upload(
143 + input,
144 + new File(["x".repeat(1_048_100)], "huge.json", { type: "application/json" }),
145 + );
146 +
147 + await expect
148 + .element(page.getByText(/^That file is/))
149 + .toHaveTextContent(
150 + "That file is 1.00 MB. Theme files are only a few KB, so this one was not read (limit 256 KB).",
151 + );
152 +});
153 +
154 function themeJsonc(name: string, background: string) {
155 return `{
156 // VS Code themes use JSONC even with a .json extension.
apps/web/src/components/settings/ThemeImportDialog.tsx
+2 -7
@@ -2,6 +2,7 @@ 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";
5 +import { formatBytes } from "../../lib/formatBytes";
6 import { cn } from "../../lib/utils";
7 import {
8 getCustomThemes,
@@ -33,15 +34,9 @@ const MAX_THEME_FILE_BYTES = 256 * 1024;
34 /** Highlighting rebuilds markup per keystroke; fall back to plain text for oversized pastes. */
35 const MAX_HIGHLIGHTED_JSON_LENGTH = 20_000;
36
36 -function formatByteSize(bytes: number): string {
37 - if (bytes >= 1024 * 1024) return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
38 - if (bytes >= 1024) return `${Math.round(bytes / 1024)} KB`;
39 - return `${bytes} bytes`;
40 -}
41 -
37 function describeOversizedThemeFile(bytes: number): string | null {
38 if (bytes <= MAX_THEME_FILE_BYTES) return null;
44 - return `That file is ${formatByteSize(bytes)}. Theme files are only a few KB, so this one was not read (limit ${formatByteSize(MAX_THEME_FILE_BYTES)}).`;
39 + return `That file is ${formatBytes(bytes)}. Theme files are only a few KB, so this one was not read (limit ${formatBytes(MAX_THEME_FILE_BYTES)}).`;
40 }
41
42 function escapeJsonHtml(value: string): string {