Repository navigation
Studio: import and export Appearance theme files - #16564
danielhanchen merged 37 commits into
Conversation
Appearance settings can now be saved as a versioned .unsloth-theme.json file and imported back, so people can share looks. Import shows a preview (swatches, what will change, warnings) before applying, and the applied toast has Undo. Look settings travel by default; sidebar layout, imported fonts and the background image are opt-in; personal settings (mode, interface scale, reduce motion, pointer cursors) never leave the device. - Move the customization rules out of the store into a pure module; sanitizeCustomizationWithIssues reports what it dropped or clamped. - Add one snapshot module that reads and applies palette, customization and glass in one pass, used by import and undo. - Parse untrusted files through own-property reads only, with size caps, an image-only background data URL, and re-encoding through the existing upload pipeline. - Every customization field must be classified, or typecheck fails. - Align the backend sidebar menu default for Appearance with the frontend (visible) and add a parity test.
- One field table (CUSTOMIZATION_FIELDS) now drives capture, parse, warning paths and the change list instead of five parallel lists. - Glass defaults live in chat-background/model.ts; undo restores the remembered glass style too, so the glass switch comes back as it was. - Warnings stop at 50 with an "And N more" line, and the imported-font loop stops at the cap again, so a hostile file can't flood the preview. - Theme backgrounds decode with decodeBase64Bytes and go through one uploadBackgroundImage helper shared with the upload control. - Export estimates the background size before encoding and re-encodes large ones as JPEG; canvasBlob rejects when an engine returns another type. The parsed file is released after the import dialog closes. - Drop the empty migration table, studioVersion, getTheme and the duplicate data-URL helpers; tests are table-driven (2064 -> 763 lines).
UI_FONT_SIZE_RANGE and SIDEBAR_NAV_DEFAULT_PINNED now live in lib/appearance-customization.ts, so the font-scale Playwright script and two contract tests read them there (Chat UI Tests (extra) failed on it).
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
- Background upload now reports a failed or superseded save, so theme import warns instead of claiming the background was applied. - Undo reverts only what the theme set and nothing changed since, so later edits and personal settings survive it; the background is restored only while it is still the one the theme set. - Fonts pushed out by the 3-font cap are listed in the import warnings. - Export leaves out names of imported fonts when the fonts themselves stay behind, and fits the background into the room the rest of the file leaves (re-encoding before giving up). - Import size guard counts bytes as up to 3 per character; an empty or font-less "assets" key no longer lifts the settings-only cap. - Background adjustments that had to change are reported; bidi and zero-width characters are stripped from theme names. - Font lists are compared without serializing their data; backend comments point at lib/appearance-customization.ts.
Export and the pre-apply undo snapshot now wait for the chat background to load from IndexedDB, so an early export keeps the background and Undo cannot delete one it did not see. Undo restores the previous background only while both the image and its adjustments are still the ones the theme set.
prepareBackgroundImage reads the width and height from the PNG, JPEG or WebP header and refuses an image over the pixel limit, or one whose header can't be read, before the browser decodes it, so a small, highly compressed file can't allocate a huge bitmap first. Uploads and theme backgrounds both go through it.
… on Undo sanitizeCustomizationWithIssues keeps the first 100 issues and counts the rest, so a theme with a huge invalid layout list can't allocate millions of issue objects before the parser's warning cap. restoreBackground now resolves with whether the background was stored, and Undo says so when the previous background couldn't be put back.
If the user picks one of the theme's imported fonts after applying, Undo keeps that selection, so it now keeps the font file too instead of reverting the font list underneath it.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e1396740da
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const rootFonts = own(rootAssets, "fonts"); | ||
| const carriesAssets = | ||
| isDict(rootAssets) && | ||
| ((Array.isArray(rootFonts) && rootFonts.length > 0) || isDict(own(rootAssets, "background"))); |
There was a problem hiding this comment.
Require a usable asset for the larger import cap
When a file exceeds MAX_THEME_FILE_CHARS_NO_ASSETS but contains only assets.background: {}, this check sets carriesAssets even though readBackground later skips the missing dataUrl. The settings-only file is therefore accepted up to the 8 MB limit instead of being rejected at the 256 KiB limit; require an actual usable embedded asset before allowing the larger cap.
Useful? React with 👍 / 👎.
| for (const key of Object.keys(value)) { | ||
| if (!known.includes(key)) { | ||
| warn({ kind: "unknown", path: `${path ? `${path}.` : ""}${key.slice(0, 64)}` }); |
There was a problem hiding this comment.
Bound unknown-key warning work
During import of an allowed asset-bearing theme with many unknown properties, this loop materializes every key and constructs a warning and path for each one before warn discards entries beyond 50. Since readThemeFile calls parseThemeFile on the renderer, a crafted 8 MB theme can still cause substantial allocation and garbage-collection work; bound key processing or count omitted keys without constructing discarded warnings.
Useful? React with 👍 / 👎.
|
Codex Review: Didn't find any major issues. 🎉 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Tested on a Colab L4 and it works: export, import preview, Apply and Undo all behave as described, in light and dark. No bugs found. Setup: Colab L4 (NVIDIA L4, 23 GB, driver 580.82.07), Ubuntu 24.04.4, Unsloth Studio built with Before / after: main has no Theme file section; the PR adds it between Code and Sidebar navigation. What I ran. I built a full look in one browser profile: Cotton Candy theme, custom accent, background and foreground for both light and dark, contrast 60, Figtree and Space Grotesk, Liquid Glass 3D, composer outline 35. The chat background is an axolotl I generated in Unsloth Studio's own Images (Z-Image-Turbo GGUF Q8_0, 1536x1024, 9 steps, 42 s on the L4). Then I exported it twice:
Then, in a second profile set to Matcha with no background and glass off:
One suggestion, not a blocker: Undo only lives in the success toast, which stays up for 5 s. If someone misses it, the only way back is a theme file of their old look. A longer duration for this toast, or holding it until it's dismissed, would make it safer. Not tested:
This run was Linux Chromium only. |
|
Pushed Codex is clean at
|
… fonts chosen after Apply over restored ones [skip ci]
…s; rejected embedded fonts clear case-variant selections [skip ci]
|
Codex Review: Didn't find any major issues. 👍 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…estores the previous look, fewer strings [skip ci]
[skip ci]
|
Codex Review: Didn't find any major issues. Swish! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
# Conflicts: # studio/frontend/src/features/chat-background/controls.tsx
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. 🚀 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@danielhanchen could we hold off merging this until the open Glass PRs land? #18520 (glass strength and lens on every glass surface) touches the same |







What
Appearance settings can now be exported as a theme file and imported back, so people can share a look or try one someone else made. It lives in Settings > Appearance under "Theme file", below Code.
<name>.unsloth-theme.json: color theme, light and dark colors, contrast, element outline, fonts and sizes, code display, chat width, composer outline and glass (including where it shows). Sidebar layout, and imported fonts plus the background image, are opt-in switches.File format
{ "kind": "unsloth-studio.appearance", "schemaVersion": 1, "name": "Midnight Matcha", "palette": "matcha", "look": { "colors": {...}, "contrast": 62, "uiFont": "Lato", "chatWidth": "wide", ... }, "glass": { "material": "frosted", "strength": { "light": 40, "dark": 15 }, "lens": "off", "menus": true, "scope": "all" }, "layout": {...}, // opt-in "fonts": [...], // opt-in "background": {...} // opt-in }lookandlayoutuse the customization field names directly. One table,FIELD_GROUPinappearance-theme/theme-file.ts, says where everyAppearanceCustomizationfield goes (look, layout, fonts or personal), and the typecheck fails if a new field has no entry. Applying a theme first resets every look setting to its default, so the same file always gives the same look; an older file just gets defaults for settings added later, and a newer one is applied best-effort with a warning.Untrusted input
JSON.parseonly, a 256 KB cap (8 MB when the file carries fonts or a background) checked before the file is read, and at most 50 warnings ("And N more").__proto__keys are never followed, and every value goes through the existingsanitizeCustomization, glass and background sanitizers.FontFace.load(), as in the font picker, or they are dropped with a warning. Font names match case-insensitively, as in CSS, and a theme never pushes a selected font out of the 3-font limit.uploadBackgroundImage). No raw CSS, no URLs fetched.Also fixed
The sidebar menu's Appearance item defaults to visible in the frontend since #16287, but the backend default (
SIDEBAR_MENU_ITEM_DEFAULTS) still said hidden, so a GET filled it in as hidden for records missing it. It now says visible, andsidebar-nav-backend-parity.test.tskeeps the two in sync.Verification
tests/appearance-theme-file.test.ts: round trip, personal fields, hostile input, case-variant and capped fonts, local fonts, layout opt-in, unloadable fonts, Undo keeping personal settings.npm run typecheck, eslint on touched files,npm run i18n:check:strict, and backendtest_personalization_settings.pypass.Before / after on two real installs
Two
install.sh --localStudios, main and this branch, driven in Chromium. The import file had a newerschemaVersion, an unknown key and an out-of-range UI font size.Settings > Appearance: the new Theme file section.
Import preview: swatches, the change groups and the three warnings.
After Apply: Matcha, contrast 64, element outline 40, UI font size clamped to 20, with the Undo toast. Undo then put every value back.