fix(desktop): use custom theme for diff view syntax highlighting
Summary
The v2 diff viewer ignored the active app theme — its syntax highlighting always used the diff library's built-in default colors, even for Superset's own built-in themes. (The code editor themed fine; only diffs were affected.) Separately, custom themes imported with their own syntax colors looked right in the moment but reverted after an app restart.
This makes diffs use the active theme, and keeps custom themes across restarts.
Type of Change
- Bug fix
Root cause
Two independent issues, both ending in "the diff doesn't use the theme's colors":
1. The theme never reached the diff renderer. The v2 diff view renders through @pierre/diffs, which does its syntax highlighting on a shared background worker pool. That pool keeps its own theme and only picks it up at creation or when explicitly updated — it ignores the per-diff theme option the app was passing. We never set a theme on the pool, so it stayed on the library's defaults (pierre-dark/pierre-light) and the app's theme was dropped. This may have regressed in #4898, which moved diffs onto the pool; the previous diff path had no pool, so it may have themed correctly.
2. Custom theme colors weren't persisted. Theme state is saved through the uiState.theme.set tRPC endpoint, whose Zod schema listed every Theme field except editor (the editor/diff color + syntax overrides). Zod strips unknown keys, so each save silently dropped editor. Imported themes looked correct during the session but reloaded without their syntax colors after a restart, falling back to a generated palette — in both the editor and the diff.
(Distinct from #3013 / #3567 / #2684 / #3569, which are about the +/- line-change colors, not syntax highlighting or persistence.)
Fix
Sync the theme to the pool — a small DiffThemeSync component, mounted next to the diff worker-pool provider, updates the pool's theme whenever the app theme changes. The library resolves the theme on the main thread, ships it to the workers, and re-renders open diffs.
Persist editor — added the missing editor field to the theme persistence schema so custom themes keep their colors across restarts.
Themes saved before this change must be re-imported once to restore their editor colors.
Testing
bun test— added a unit test for the pool theme optionsbun run typecheckandbun run lint— clean- Manual: imported a custom theme with distinct syntax colors → diff tokens render in the theme's colors instead of the library default; switching themes updates open diffs live; colors now survive an app restart
How to reproduce
- Download
monokai-pro-superset-theme.json— a custom theme with a fulleditor.syntaxblock. - Settings → Appearance → Import theme → select it → activate.
- Open any diff → syntax tokens render in the theme's colors (pink keywords
#FF6188, yellow strings#FFD866, green functions#A9DC76), not the library default. - Reload (Cmd-R) → colors persist.
Screenshots
Here's how the diff viewer looks with the custom Monokai Pro theme
Theme applied correctly
Theme survives cmd+r reload
Summary by cubic
Fixes diff syntax theming by applying the active app theme to the @pierre/diffs worker pool and persisting Theme.editor. Diff views now use the right colors for custom and built-in themes, survive reloads, and pool/per-item diff options stay in sync; if you saved a custom theme before this change, re-import it once to restore editor syntax colors.
-
Bug Fixes
- Sync the active theme to the
@pierre/diffsworker pool viaDiffThemeSync, callingsetRenderOptionson theme changes and sharing diff/tokenize options throughDIFF_POOL_RENDER_OPTIONSsoCodeViewitems and the pool use the same settings. - Persist
Theme.editorby adding aneditorfield to the ZodthemeSchema(colorsandsyntaxas records), fixing custom theme syntax being dropped on save and lost after restart. - Guard the pool call with optional chaining and log
setRenderOptionsrejections withconsole.errorto avoid unhandled promise rejections.
- Sync the active theme to the
-
Refactors
- Constrain
DIFF_POOL_RENDER_OPTIONSwithsatisfies Partial<RenderDiffOptions>to catch invalid or renamed render-option keys at build time.
- Constrain
Summary by CodeRabbit
Summary by CodeRabbit
-
New Features
- Diff views now synchronize with the active app theme for more consistent styling.
-
Bug Fixes
- Custom theme editor color/syntax overrides now persist correctly after reopening.
- Improved diff rendering consistency by applying shared worker-pool diff render options so tokenization stays aligned.
-
Tests
- Added unit tests to verify diff theme naming and core diff render-option settings.