Skip to content

fix(frontend): make inline code readable under default 'auto' syntax theme - #752

Merged
unhappychoice merged 3 commits into
mainfrom
fix/inline-code-unreadable-on-auto-theme
May 31, 2026
Merged

unhappychoice merged 3 commits into
mainfrom
fix/inline-code-unreadable-on-auto-theme

Conversation

@unhappychoice

@unhappychoice unhappychoice commented May 31, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Inline <code> and fenced code blocks without a language rendered with white text on a transparent background under the default config, making them unreadable on light themes (reported in mdts default theme/configuration is unreadable #749).
  • Root cause: MarkdownCode.tsx looked up theme metadata directly in SYNTAX_HIGHLIGHTER_THEMES, which has no entry for the default value 'auto' (nor for unknown values), so both color and backgroundColor resolved to undefined/white.
  • Introduce resolveSyntaxHighlighterThemeValue and useSyntaxHighlighterThemeMeta in useSyntaxHighlighterTheme.ts, resolving 'auto' to 'vs' / 'atomDark' based on the active MUI palette mode and falling back to 'atomDark' for unknown values.
  • useSyntaxHighlighterTheme itself now shares the same resolver, removing the duplicated 'auto' branch.

Test plan

  • npx jest test/unit/components/Content/MarkdownContent/MarkdownRenderer/MarkdownCode.test.tsx (4 passed, 1 snapshot updated to include the resolved background color)
  • Full frontend npx jest --selectProjects test shows no new failures (the 3 pre-existing SettingsDialog snapshot failures are MUI emotion hash churn unrelated to this change and also fail on main)
  • Manual: open a Markdown file containing inline code and a fenced block without a language under the default config, in both light and dark system color schemes, and confirm the code renders with proper contrast.

Fixes #749

Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor
    • Centralized and simplified syntax-highlighter theme resolution for more consistent theming across light/dark modes.
  • Bug Fixes / UX
    • Inline code and code blocks now use improved theme metadata, yielding more accurate foreground/background colors and better readability.

…theme

The inline code `<code>` fallback in MarkdownCode looked up the active
syntax highlighter theme directly in SYNTAX_HIGHLIGHTER_THEMES, which
has no entry for the default value 'auto'. The lookup returned
undefined, so color fell through to '#fff' (white) and background to
undefined (transparent), making inline code and fenced code blocks
without a language unreadable on light backgrounds.

Resolve 'auto' to the effective theme value ('vs' in light mode,
'atomDark' in dark mode) before the metadata lookup, and fall back to
'atomDark' for unknown values so color/background stay consistent.

Fixes #749

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@netlify

netlify Bot commented May 31, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for mdts-unhappychoice ready!

Name Link
🔨 Latest commit bebffd2
🔍 Latest deploy log https://app.netlify.com/projects/mdts-unhappychoice/deploys/6a1c2b756735e60008b83c83
😎 Deploy Preview https://deploy-preview-752--mdts-unhappychoice.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai

coderabbitai Bot commented May 31, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@unhappychoice, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 21 minutes and 51 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f666aeaa-fbfc-4268-81c0-d9a435aa5783

📥 Commits

Reviewing files that changed from the base of the PR and between 30f3c54 and bebffd2.

📒 Files selected for processing (1)
  • packages/frontend/src/hooks/useSyntaxHighlighterTheme.ts
📝 Walkthrough

Walkthrough

This PR centralizes syntax highlighter theme resolution into helpers (resolveSyntaxHighlighterThemeValue, useSyntaxHighlighterThemeMeta), refactors useSyntaxHighlighterTheme to use the resolver, and updates MarkdownCode to consume theme metadata for inline <code> styling.

Changes

Syntax Highlighter Theme Centralization

Layer / File(s) Summary
Theme resolution and metadata helpers
packages/frontend/src/hooks/useSyntaxHighlighterTheme.ts
resolveSyntaxHighlighterThemeValue helper resolves 'auto' to a mode-specific theme. New useSyntaxHighlighterThemeMeta hook returns metadata (type, color) for a resolved theme with atomDark fallback. useSyntaxHighlighterTheme refactored to use the resolver, removing duplicate 'auto' handling.
MarkdownCode component integration
packages/frontend/src/components/Content/MarkdownContent/MarkdownRenderer/MarkdownCode.tsx
MarkdownCode imports and calls useSyntaxHighlighterThemeMeta, then applies the resolved theme metadata (type, color) to inline <code> element styling, replacing prior SYNTAX_HIGHLIGHTER_THEMES.find(...) lookups.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A rabbit's refactor, tidy and neat,
Hooks shared the theme so the colors all meet,
auto now resolves with no duplicate song,
Inline code shines—short and strong,
Hop, the renderer hums along.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the main change: fixing inline code readability under the default 'auto' syntax theme by resolving it to theme-appropriate colors.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/inline-code-unreadable-on-auto-theme

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented May 31, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.41%. Comparing base (5c680e8) to head (bebffd2).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #752      +/-   ##
==========================================
+ Coverage   99.35%   99.41%   +0.06%     
==========================================
  Files          69       69              
  Lines        1543     1547       +4     
  Branches      366      366              
==========================================
+ Hits         1533     1538       +5     
+ Misses          9        8       -1     
  Partials        1        1              
Flag Coverage Δ
frontend 99.43% <100.00%> (+0.09%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/frontend/src/hooks/useSyntaxHighlighterTheme.ts (1)

60-60: ⚡ Quick win

Downgrade: atomDark fallback is safe with current theme constants

SYNTAX_HIGHLIGHTER_THEMES includes { value: 'atomDark' } (in packages/frontend/src/constants.ts), so SYNTAX_HIGHLIGHTER_THEMES.find(...'atomDark')! won’t hit undefined today. The non-null assertion is now mainly a maintainability concern—either remove it or add a short comment that 'atomDark' must remain present.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/frontend/src/hooks/useSyntaxHighlighterTheme.ts` at line 60, The
non-null assertion on SYNTAX_HIGHLIGHTER_THEMES.find(t => t.value ===
'atomDark')! in useSyntaxHighlighterTheme.ts is a maintainability risk; either
remove the trailing '!' to let the type reflect possible undefined and handle
that case, or keep it but add a short comment near the expression (and/or in
constants.ts) stating that 'atomDark' is required to exist in
SYNTAX_HIGHLIGHTER_THEMES; update any surrounding code (e.g., the function that
uses this value) to safely handle undefined if you remove the assertion (provide
a fallback or runtime check).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/frontend/src/hooks/useSyntaxHighlighterTheme.ts`:
- Line 56: The function declaration for useSyntaxHighlighterThemeMeta exceeds
the 120-char limit due to the inline return type; refactor the signature to
break the return type onto the next line or introduce a short type alias (e.g.,
type ThemeMeta = typeof SYNTAX_HIGHLIGHTER_THEMES[number]) and use that alias as
the return type, updating the function declaration
(useSyntaxHighlighterThemeMeta) to keep each line under 120 characters and
satisfy ESLint.

---

Nitpick comments:
In `@packages/frontend/src/hooks/useSyntaxHighlighterTheme.ts`:
- Line 60: The non-null assertion on SYNTAX_HIGHLIGHTER_THEMES.find(t => t.value
=== 'atomDark')! in useSyntaxHighlighterTheme.ts is a maintainability risk;
either remove the trailing '!' to let the type reflect possible undefined and
handle that case, or keep it but add a short comment near the expression (and/or
in constants.ts) stating that 'atomDark' is required to exist in
SYNTAX_HIGHLIGHTER_THEMES; update any surrounding code (e.g., the function that
uses this value) to safely handle undefined if you remove the assertion (provide
a fallback or runtime check).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: bfd62649-e648-44da-8bb4-f0888779f974

📥 Commits

Reviewing files that changed from the base of the PR and between 10ec183 and 30f3c54.

📒 Files selected for processing (1)
  • packages/frontend/src/hooks/useSyntaxHighlighterTheme.ts

@unhappychoice
unhappychoice merged commit 5a7f365 into main May 31, 2026
9 checks passed
@unhappychoice
unhappychoice deleted the fix/inline-code-unreadable-on-auto-theme branch May 31, 2026 12:45
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.

mdts default theme/configuration is unreadable

1 participant