Repository navigation
fix(frontend): make inline code readable under default 'auto' syntax theme - #752
Conversation
…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]>
✅ Deploy Preview for mdts-unhappychoice ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Warning Review limit reached
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 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 configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThis PR centralizes syntax highlighter theme resolution into helpers ( ChangesSyntax Highlighter Theme Centralization
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…-len Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/frontend/src/hooks/useSyntaxHighlighterTheme.ts (1)
60-60: ⚡ Quick winDowngrade:
atomDarkfallback is safe with current theme constants
SYNTAX_HIGHLIGHTER_THEMESincludes{ value: 'atomDark' }(inpackages/frontend/src/constants.ts), soSYNTAX_HIGHLIGHTER_THEMES.find(...'atomDark')!won’t hitundefinedtoday. 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
📒 Files selected for processing (1)
packages/frontend/src/hooks/useSyntaxHighlighterTheme.ts
Summary
<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).MarkdownCode.tsxlooked up theme metadata directly inSYNTAX_HIGHLIGHTER_THEMES, which has no entry for the default value'auto'(nor for unknown values), so bothcolorandbackgroundColorresolved to undefined/white.resolveSyntaxHighlighterThemeValueanduseSyntaxHighlighterThemeMetainuseSyntaxHighlighterTheme.ts, resolving'auto'to'vs'/'atomDark'based on the active MUI palette mode and falling back to'atomDark'for unknown values.useSyntaxHighlighterThemeitself 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)npx jest --selectProjects testshows no new failures (the 3 pre-existingSettingsDialogsnapshot failures are MUI emotion hash churn unrelated to this change and also fail onmain)Fixes #749
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
🤖 Generated with Claude Code
Summary by CodeRabbit