Skip to content

Let UI themes declare matching Pierre code themes - #1459

Merged
SawyerHood merged 4 commits into
mainfrom
bb/enable-custom-theme-exports-thr_g76dukd3ew
Aug 13, 2026
Merged

SawyerHood merged 4 commits into
mainfrom
bb/enable-custom-theme-exports-thr_g76dukd3ew

Conversation

@SawyerHood

Copy link
Copy Markdown
Collaborator

Summary

  • let a custom or plugin UI theme ship Pierre / VS Code JSON so diffs and file preview match the palette
  • make the code theme follow the active appearance instead of adding a second picker
  • map each built-in palette to a matching Shiki pair, with first-party light files for Nord and Dracula
  • register those themes with Pierre and push them into the worker pool, which ignores per-component theme options
  • stamp registered theme names so Pierre does not fall back to pierre-light

This is a narrower product choice than the original issue: there is no independent user code-theme selector. Switching the UI theme is what selects the code colors.

Validation

  • pnpm exec turbo run test --filter=@bb/domain --filter=@bb/server --filter=@bb/cli --filter=@bb/sdk
  • pnpm exec turbo run typecheck --filter=@bb/domain --filter=@bb/app
  • browser QA on the worktree app: Ocean custom theme, Nord light, and Dracula light file preview / diffs

Risks

Pierre custom themes must use a name that matches the registered id. The worker pool is a singleton, so a theme switch has to call setRenderOptions or File/FileDiff keep the previous pair.

Closes #1239

AGENT GENERATED: by Grok 4.6

Code highlighting now follows the active appearance. Custom and plugin
themes can ship Pierre / VS Code JSON; built-in palettes use a matching
Shiki pair, with first-party light files for Nord and Dracula.

Closes #1239
useAppTheme is eager. Registering custom code themes from that hook pulled
@pierre/diffs into the boot payload and blew the bundle budget. Move
registration next to the worker-pool sync, which already loads Pierre.
@SawyerHood

Copy link
Copy Markdown
Collaborator Author

🚨 SLOP COP 🚨 · review

I am SlopCop. I am reviewing this pull request for security, code quality, performance, architecture, and end-to-end behavior.

Comment thread apps/app/src/hooks/useAppTheme.ts Outdated

// Register Pierre files during render so child File/FileDiff mounts and the
// worker-pool sync effect see the resolved names on the same pass.
if (appearance?.resolvedCodeTheme !== undefined) {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

🚨 slopcop/review — This call changes shared state and the DOM during React render.

applyResolvedCodeTheme writes document attributes and synchronously notifies mounted external-store users. A live config update can therefore update children while the parent render is active. Please move this work to a layout effect or use a React-owned provider with a safe snapshot.

function registerResolvedCodeThemeFiles(): void {
const resolved = getResolvedCodeTheme();
for (const [name, theme] of Object.entries(resolved.files)) {
if (registeredFileNames.has(name)) continue;

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

🚨 slopcop/review — Custom code-theme edits keep the first registered file until the page restarts.

The server reuses a stable name after a user edits the JSON and runs bb theme set again. This permanent name set skips the new content. Pierre also rejects duplicate registrations. Please use a content-versioned registration name or another replacement mechanism, and add a two-update test.

.strict();
export type CodeThemePair = z.infer<typeof codeThemePairSchema>;

export const vscodeThemeJsonSchema = jsonObjectSchema.refine(

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

🚨 slopcop/review — A deeply nested theme file can make the system configuration route return 500.

jsonObjectSchema.safeParse can throw a RangeError during recursive validation. The server calls this parser outside its catch. I reproduced the failure with a 2,000-level object below the 256 KB limit. Please contain parser exceptions, limit object depth, and validate the actual VS Code theme fields before activation.

Comment thread plugins/github/app.tsx Outdated
};
}

function useHostCodeTheme(): { dark: string; light: string } {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

🚨 slopcop/review — Each open patch creates its own document observer.

The host writes both theme attributes before its equality check. Even same-value writes create mutation records. Every observer then stores a new object, so an unrelated config refresh can rerender every visible patch. Please subscribe once at the panel or SDK boundary and share one stable theme snapshot.

@SawyerHood SawyerHood left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

🚨 SLOP COP 🚨 · review

ELI5: This change lets each app palette choose matching code colors. Built-in themes work, but custom themes can fail or stay stale.

I found four main defects:

  1. P1: A deeply nested JSON file can throw a RangeError and make /system/config return 500.
  2. P2: A custom theme edit keeps the first registered JSON until the page restarts.
  3. P2: Theme application changes the DOM and an external store during React render.
  4. P2: Each open GitHub patch creates an observer, so same-value writes can rerender every visible patch.

The server also accepts malformed files and unknown bundled names. Pierre then rejects them and keeps the prior code theme active.

The configuration path reads theme files synchronously and sends them with every response. Nord added about 26.7 KB in my local check. Two custom files can add about 512,000 characters.

The change duplicates the worker-pool theme provider in two views. The GitHub plugin also duplicates the host theme reader and observer. A shared provider and an experimental SDK hook would reduce this duplication.

QA results:

  • The browser changed Default, Nord, and Dracula without a reload. The host published the correct dark and light names.
  • The affected Turbo type checks passed.
  • The domain and SDK suites passed.
  • The focused server and CLI tests passed.
  • The desktop smoke test passed alone after a timeout during the parallel suite.
  • git diff --check passed.

I would not merge this revision until the P1 and P2 defects are fixed. I posted a comment-only review as required.

SawyerHood and others added 2 commits August 13, 2026 03:12
Move theme application out of render, version Pierre registrations by
file content, reject oversized theme JSON without taking down config,
and share one host theme subscription in the GitHub plugin.
The plugin bundle also loads outside a DOM, such as in the CLI bundle
test. A module-eval `document` access threw a ReferenceError there.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@SawyerHood
SawyerHood merged commit e2b03fc into main Aug 13, 2026
10 checks passed
@SawyerHood
SawyerHood deleted the bb/enable-custom-theme-exports-thr_g76dukd3ew branch August 13, 2026 04:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Let a UI theme declare its own code theme

1 participant