Skip to content

fix(app): render code blocks with theme-aware Shiki palette#2447

Open
magic-peach wants to merge 1 commit into
different-ai:devfrom
magic-peach:fix/code-block-dark-theme-2440
Open

fix(app): render code blocks with theme-aware Shiki palette#2447
magic-peach wants to merge 1 commit into
different-ai:devfrom
magic-peach:fix/code-block-dark-theme-2440

Conversation

@magic-peach

@magic-peach magic-peach commented Jul 3, 2026

Copy link
Copy Markdown

Summary

  • Code blocks in assistant messages (and artifact/extension markdown) were always highlighted with Shiki's github-light theme, so tokens were unreadable in dark mode.
  • Switched codeToHtml to dual themes (themes: { light: "github-light", dark: "github-dark" }, defaultColor: "light"), which emits the dark palette as --shiki-dark* CSS variables alongside the unchanged light colors.
  • Added a small CSS rule in src/app/index.css that activates the dark variables under .dark / [data-theme="dark"] (matching the app's existing dark variant selectors).

Why

  • Fixes low-contrast/unreadable code in dark mode. The dual-theme approach also means code blocks flip instantly when the user switches theme — no re-parse or re-highlight needed, unlike checking the DOM theme at highlight time (the app sets data-theme on the root, not a dark class, so the snippet suggested in the issue would not have matched).

Issue

Scope

  • apps/app/src/components/markdown/markdown.tsx (chat message renderer, the file cited in the issue)
  • apps/app/src/react-app/domains/session/surface/markdown.tsx (artifact preview / extension detail renderer — identical hardcoded theme, same 2-line fix)
  • apps/app/src/app/index.css (one CSS rule to activate the dark palette)

Out of scope

  • src/components/ui/code-block.tsx (already takes theme as a prop; callers can opt in separately)
  • Any change to light-mode rendering — the light palette is still emitted inline exactly as before.

Testing

Ran

  • pnpm install
  • pnpm --filter @openwork/app typecheck

Result

  • pass/fail: pass (no type errors)

CI status

  • pass: Vercel Preview Comments, Vercel openwork-landing
  • code-related failures: none
  • external/env/auth blockers: the three "Vercel – openwork-app / openwork-den / openwork-den-worker-proxy" checks fail with "Authorization required to deploy" — a fork-deploy authorization gate, unrelated to this change (which only touches the Electron app's renderer, not any Vercel-deployed app).

Manual verification

  1. Rendered real output through the repo's own shiki@4 with the new options and confirmed the HTML contains both the inline light colors and --shiki-dark / --shiki-dark-bg variables.
  2. Loaded that output in a page with the new CSS rule and captured light vs dark side by side (screenshot below).
  3. In-app repro for reviewers: Settings > Appearance > Dark, send a message containing a fenced code block, confirm tokens use the github-dark palette; switch back to Light and confirm rendering is unchanged.

Evidence

before/after in light and dark themes

Left: light theme after the fix (unchanged). Right top: current dark-mode bug (light palette on dark background). Right bottom: dark theme after the fix.

I was not able to capture an in-app video for this one — the verification above was done against the real Shiki pipeline and CSS outside Electron; the 3-step in-app repro is listed for the reviewer.

Risk

  • Low. Light mode output is byte-identical apart from added CSS variables; the dark override is scoped to .shiki elements under the dark theme selectors.

Rollback

  • Revert this commit; no data or config migrations involved.

Code blocks in assistant messages were highlighted with a hardcoded
github-light theme, making tokens unreadable in dark mode. Emit both
palettes via Shiki's dual-theme CSS variables and switch to github-dark
when the app theme is dark.

Fixes different-ai#2440
@vercel

vercel Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
openwork-landing Ready Ready Preview, Comment, Open in v0 Jul 3, 2026 6:39pm

@vercel

vercel Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

@magic-peach is attempting to deploy a commit to the Different AI Team on Vercel.

A member of the Team first needs to authorize it.

@magic-peach

Copy link
Copy Markdown
Author

@benjaminshafii could you please review my pr?

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.

Code block dark mode bug - Shiki theme hardcoded to github-light

1 participant