Skip to content

Studio: import and export Appearance theme files - #16564

Merged
danielhanchen merged 37 commits into
unslothai:mainfrom
Etherll:Etherll/appearance-settings-import-export
Nov 20, 2026
Merged

danielhanchen merged 37 commits into
unslothai:mainfrom
Etherll:Etherll/appearance-settings-import-export

Conversation

@Etherll

@Etherll Etherll commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

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.

  • Export writes <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.
  • Import opens a preview before anything changes: the name, light and dark swatches, what will change, and any warnings (unknown keys, invalid or out-of-range values, an unknown color theme, a file from a newer Studio). Apply shows a toast with Undo, which puts back the previous look.
  • Personal settings never leave the device and are never overwritten, Undo included: light/dark/system mode, interface scale, reduce motion and pointer cursors.

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
}

look and layout use the customization field names directly. One table, FIELD_GROUP in appearance-theme/theme-file.ts, says where every AppearanceCustomization field 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.parse only, 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").
  • Fields are read through own-property checks, so __proto__ keys are never followed, and every value goes through the existing sanitizeCustomization, glass and background sanitizers.
  • Embedded fonts must load through 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.
  • The background must be a PNG, JPEG or WebP base64 data URL and is decoded and re-encoded through the normal upload path (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, and sidebar-nav-backend-parity.test.ts keeps 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.
  • Frontend node suite, npm run typecheck, eslint on touched files, npm run i18n:check:strict, and backend test_personalization_settings.py pass.

Before / after on two real installs

Two install.sh --local Studios, main and this branch, driven in Chromium. The import file had a newer schemaVersion, an unknown key and an out-of-range UI font size.

Settings > Appearance: the new Theme file section.

Theme file section

Import preview: swatches, the change groups and the three warnings.

Import preview

After Apply: Matcha, contrast 64, element outline 40, UI font size clamped to 20, with the Undo toast. Undo then put every value back.

Applied with Undo

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).
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-19T11:57:05.537588Z 4e17eb1 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

- 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.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

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.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

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.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

… 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.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

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.
@Etherll

Etherll commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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")));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment on lines +87 to +89
for (const key of Object.keys(value)) {
if (!known.includes(key)) {
warn({ kind: "unknown", path: `${path ? `${path}.` : ""}${key.slice(0, 64)}` });

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 63fb374224

ℹ️ 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".

@LeoBorcherding

Copy link
Copy Markdown
Collaborator

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 setup.sh --local and driven in headless Chromium at 1280x860, 2x. AFTER is the PR head 03d9f3f233, BEFORE is the merge base bbee0dc04f, both on the same VM. The two commits pushed since (e1396740da, 63fb374224) change the Undo path for imported fonts and the JPEG header reader. This run used neither (no imported fonts, PNG background), so these results still hold for what's below.

Before / after: main has no Theme file section; the PR adds it between Code and Sidebar navigation.

Settings > Appearance on main and on the PR, light

Same pair in dark

Settings > Appearance on main and on the PR, dark

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:

  • Background switch off: a 975-byte file with the palette, colors, typography, code, chat and glass. No mode, scale or language in it.
  • Background switch on: 2.15 MB, with the PNG and its adjustments under assets.background.

Then, in a second profile set to Matcha with no background and glass off:

step result
import the file with the background preview shows the name, author, light and dark swatches, and 6 change chips; "Also apply fonts and background image" defaults on
Apply theme colors, fonts, glass and background all applied, the mode you were in stays as it was, toast with Undo
Undo back to Matcha, accent #437A22, default fonts, glass off, no background; "Previous look restored"
same flow in dark same result, with the dark colors from the file
file with schemaVersion: 2, an unknown key, palette bubble-tea, contrast 250, accent "pink", UI font size 99 6 warnings, one each; after Apply, contrast is 100, font size 20, theme Standard
truncated JSON toast "This file isn't a valid Unsloth theme.", no dialog, nothing changes

Import preview in light and dark

Previous look, Apply with the Undo toast, then Undo

The imported theme in chat, light and dark

Edge-case warnings and the export dialog

Six warnings from the edge-case file

Export dialog with the background switch on

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:

  • imported font files and the font-Undo fix in e1396740da
  • the sidebar layout opt-in
  • the JPEG re-encode for a background over the size cap, and JPEG backgrounds in general (63fb374224 touches the JPEG header reader)
  • the backend SIDEBAR_MENU_ITEM_DEFAULTS change
  • Unsloth Desktop (Tauri) and native macOS glass

This run was Linux Chromium only.

@LeoBorcherding

LeoBorcherding commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

Pushed b5ce5389 and 74669704. A theme exported on macOS can carry the native-only glass material (macos). Imported on Windows or Linux, that material can't render, so it now becomes Liquid 3D. The conversion is applied to the import plan itself (portableGlass in appearance-theme/snapshot.ts, called from import-theme-dialog.tsx), not at write time. That way Undo compares against what was actually applied, and it puts the previous glass back instead of treating the conversion as a later edit. On macOS the theme is applied unchanged. A test covers import, then Undo, restoring the old glass, plus the macOS case.

Codex is clean at 74669704 on the review mirror (LeoBorcherding/unsloth#740). The 55 appearance-theme tests pass, and the frontend typecheck finished with no errors on the Mac.

e24c6e04 (test-only): the Undo-baseline test now builds a full ThemeApplyPlan, which the --tests typecheck in Frontend CI requires. Codex is clean at e24c6e04 on the mirror.

dec0731b: a merge of main, which conflicted in stores/appearance-custom-store.ts. Main (#16751) changed the Reduce motion default to Off inside the customization rules this PR moves to lib/appearance-customization.ts; the new default is carried into the moved rules, and the tests that pinned the old default now expect Off. Codex is clean at dec0731b; CI is rerunning.

… fonts chosen after Apply over restored ones

[skip ci]
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…s; rejected embedded fonts clear case-variant selections

[skip ci]
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 13, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: eca6b5c7bc

ℹ️ 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".

chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 14, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 14, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 14, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 14, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: e735b9c461

ℹ️ 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".

# Conflicts:
#	studio/frontend/src/features/chat-background/controls.tsx
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 19, 2026
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 4e17eb1490

ℹ️ 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".

@LeoBorcherding

Copy link
Copy Markdown
Collaborator

@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 features/chat-background/model.ts and locale files, and the exported theme should round-trip whatever it settles on. #18030, #18032, #18530 and #18531 are in the same area. I'm stacking a copy of this branch on top of them on my fork to resolve the conflicts, and I'll post the resolved diff here so updating it is quick.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants