ollama - ✅(Solved) Fix app/ui: centralize theme detection and tokenize only the active theme in code blocks [1 pull requests, 2 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
ollama/ollama#15998Fetched 2026-05-07 03:31:55
View on GitHub
Comments
2
Participants
2
Timeline
4
Reactions
0
Participants
Timeline (top)
commented ×2cross-referenced ×1labeled ×1

Fix Action

Fixed

PR fix notes

PR #16002: app/ui: centralize theme detection and tokenize only the active theme in code blocks

Description (problem / solution / changelog)

Every code block in a chat message previously ran syntax highlighting twice (once for light mode, once for dark mode), doubling the Shiki processing time. Theme names were also hardcoded across files.

This change:

  1. Exports THEME_LIGHT and THEME_DARK from highlighter.ts.
  2. Creates a useTheme hook to detect and react to system theme changes.
  3. Refactors CodeBlock to tokenize only the active theme on mount, lazily caching tokens per theme for instant switching.
  4. Skips tokenization for languages not registered in the highlighter.

Fixes #15998

Changed files

  • app/ui/app/src/components/StreamingMarkdownContent.tsx (modified, +33/-40)
  • app/ui/app/src/hooks/useTheme.ts (added, +18/-0)
  • app/ui/app/src/lib/highlighter.ts (modified, +5/-2)
RAW_BUFFERClick to expand / collapse

What is the issue?

Every code block in a chat message runs syntax highlighting twice — once for light mode and once for dark mode. Both results are rendered as two separate <pre> elements, and CSS hides the inactive one. On a chat with hundreds of code blocks, this doubles the Shiki processing time for no visible benefit.

There's also no centralized way to know which theme is currently active. The theme names are hardcoded as string literals scattered across files.

Why it matters Shiki's TextMate grammar regex is the single most expensive operation during chat loading. Cutting it in half by only tokenizing the active theme has a massive impact.

Relevant log output

OS

Linux, macOS

GPU

Apple

CPU

Apple

Ollama version

No response

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

ollama - ✅(Solved) Fix app/ui: centralize theme detection and tokenize only the active theme in code blocks [1 pull requests, 2 comments, 2 participants]