Skip to content

fix: make resource type code blocks theme-aware in dark mode - #377

Merged
DariuszPorowski merged 6 commits into
mainfrom
nicolejms-fix-dark-mode-code-blocks
Sep 30, 2026
Merged

DariuszPorowski merged 6 commits into
mainfrom
nicolejms-fix-dark-mode-code-blocks

Conversation

@nicolejms

@nicolejms nicolejms commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #340

Problem

On a resource type detail page (for example, Radius.Core/environments), code samples used a fixed light background but inherited their foreground color from the active theme. In dark mode this produced near-white text on a near-white background.

The page also used fixed GitHub colors for surrounding tables, links, borders, and status text, which did not adapt to Backstage branded themes and could provide insufficient contrast on Material-UI Paper surfaces.

Fix

  • Code blocks and inline code now set explicit, matched foreground and background colors for light and dark mode.
  • The copy control, including its border, hover state, and URL-encoded SVG icon, follows the code-surface palette.
  • Non-code UI uses Backstage semantic theme tokens for paper backgrounds, primary and secondary text, links, dividers, and hover states.
  • Required markers use the theme's primary text color rather than low-contrast red text.
  • The unused codeSnippetContainer style block was removed.

Tests

The ResourceTypeDetailPage suite now has 34 passing tests, including regression coverage that:

  • verifies overview code foreground and background in light and dark mode;
  • verifies copy-control colors in both themes;
  • renders fenced code inside a table property description and checks the JSS-computed colors; and
  • supplies a custom branded palette and verifies surrounding page elements use its semantic tokens.

Validation completed with yarn tsc, yarn lint:all, yarn format:check, the focused 34-test suite, and the Impeccable UI detector.

Code samples and the surrounding detail page were painted with fixed
light-mode colors, so under the dark theme they rendered near-white text
on a near-white background and became unreadable.

Resolve every color on the page through a getThemeColors() token set keyed
off palette.type, covering code blocks, inline code, the copy button and
its clipboard icon, tables, links, and muted text. Light mode keeps its
existing values; dark mode uses the matching GitHub dark palette.

Fixes #340

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Signed-off-by: nicolejms <nicolej@microsoft.com>
@nicolejms
nicolejms requested review from a team as code owners September 21, 2026 22:27
@github-actions

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

nithyatsu
nithyatsu previously approved these changes Sep 22, 2026

@nithyatsu nithyatsu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approving — the fix is correct and well-scoped. The <pre> now sets both background and foreground (with <code> inheriting on a transparent background), light-mode values are unchanged so it's a true no-op for the existing theme, and every hardcoded hex in the file now routes through the single getThemeColors token set. Nice catch threading the icon fill through clipboardIconUrl(fill) — the url-encoded SVG would otherwise have stayed dark-gray on dark.

Three non-blocking suggestions inline: hardcoded GitHub hexes vs. Backstage theme tokens, some dead code that could be deleted rather than refactored, and a gap in what the new tests cover. None need to block the merge.

Comment thread plugins/plugin-radius/src/components/resourcetypes/ResourceTypeDetailPage.tsx Outdated
Comment thread plugins/plugin-radius/src/components/resourcetypes/ResourceTypeDetailPage.tsx Outdated
nicolejms and others added 5 commits September 28, 2026 14:47
Use semantic Backstage tokens for non-code surfaces so branded and dark
themes retain their own paper, text, link, and divider colors. Keep the
GitHub palette scoped to code samples and their copy control, and remove
the unused code snippet style block.

Extend regression coverage to property-description code, copy controls,
and custom semantic theme tokens.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Signed-off-by: nicolejms <nicolej@microsoft.com>
Signed-off-by: nicolejms <nicolej@microsoft.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Signed-off-by: nicolejms <nicolej@microsoft.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

@nithyatsu nithyatsu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the follow-up — all three earlier suggestions are addressed. The page now takes its non-code colors from the Backstage theme, the GitHub palette is limited to code blocks and the copy button, the unused style block is gone, and RT-31–34 cover the copy button, code blocks inside property descriptions, and a custom theme. LGTM.

@DariuszPorowski
DariuszPorowski merged commit 4bb8830 into main Sep 30, 2026
5 checks passed
@DariuszPorowski
DariuszPorowski deleted the nicolejms-fix-dark-mode-code-blocks branch September 30, 2026 03:33
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 blocks are unreadable on resource type details pages in dark mode

4 participants