Repository navigation
fix(theme): give syntax punctuation its own AA-passing colour - #5414
Conversation
Fixes meta#5386. --color-syntax-punctuation borrowed --color-text-disabled, a token WCAG deliberately exempts from the normal-text contrast requirement. Three themes measured under 4.5:1 against their syntax background: neutral (2.42:1 light, 2.53:1 dark), chocolate (3.06:1/2.56:1), matcha (3.83:1/2.73:1). butter/gothic/stone/y2k already had a passing punctuation colour of their own. The shared default now points at --color-text-secondary (already used for --color-syntax-comment, already AA). The three failing themes get a dedicated punctuation colour instead of inheriting the default, since each defines its own syntax palette: neutral #6e6e6e / #a0a0a0 (4.89:1 / 7.57:1) chocolate #9e622e / #cb884d (4.84:1 / 6.12:1) matcha #566a39 / #92af6a (5.19:1 / 7.02:1) Adds scripts/check-syntax-punctuation-contrast.test.mjs, resolving --color-syntax-punctuation/background through light-dark()/var() indirection (the pattern from meta#4446's badge contrast guard) and holding every theme to AA in both colour schemes. Regenerated the CLI theme template bundle (pnpm bundle:cli-themes) for the three changed themes.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR No new or modified components detected. Bundle Size Summary
Accessibility AuditStatus: No accessibility violations detected. Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
|
Hi @HelloOjasMutreja, nice catch - I verified the headline numbers independently (WCAG 2.1 relative luminance, 4.5:1): neutral light/dark 4.89:1 / 7.57:1, chocolate 4.84:1 / 6.12:1, matcha 5.19:1 / 7.02:1 all clear AA. Good. Two things I'd want considered before this lands: 1. The shared default now makes punctuation visually identical to comments. 2. The resolver only handles hex - it's worth failing loud when it can't resolve. Minor: consider reusing the badge guard's resolver instead of a second copy in Overall a clean, well-scoped fix. The two asks are: make a deliberate call on punctuation-vs-comment colour identity for the default themes, and make the resolver fail loud on unsupported colour formats. |
…t guard Per @gonzoblasco's review on meta#5414: resolve() returned null for anything that wasn't hex, so a theme using oklch()/hsl()/rgb() would silently drop out of the resolved rows with no clue why — the length guard would just report the wrong count with no hint which theme or format broke it. Throw with the actual unresolvable value instead. All seven themes still resolve cleanly through hex/light-dark()/var() today, so this is a no-op change in current behavior.
|
Thanks for the independent WCAG verification, and for catching the resolver's silent-null gap. On #2 (fail loud): pushed in 1c20165. On #1 (punctuation-vs-comment identity): checked this carefully, and I don't think it's actually a regression from this PR. None of butter/gothic/stone/y2k inherit the shared default — all seven themes (including these four) call So for the four you flagged, checking each theme file directly:
The shared default I changed ( On the "share the resolver" note: agreed it's the right shape long-term, holding off on it here since it'd mean touching |
|
Great follow-up, and thanks for checking the actual theme files - you're right, and I was wrong on #1. I should have verified the shipped themes against the source before raising it: I assumed the four inherited the shared default, but you've shown all seven define their own full And confirming the specific values makes it conclusive: butter/stone/y2k already had Glad #2 landed cleanly with the loud-fail commit (1c20165) - that closes the real gap I flagged. And agreed on the resolver-sharing being a good follow-up rather than scope creep here; splitting it out later keeps this fix tight. Nice work on this one. |
cixzhang
left a comment
There was a problem hiding this comment.
Thanks — reproduced every number from real pixels: seven themes, both schemes, and transparent-background container="section". gonzoblasco's two points are settled. Merging once Vercel clears.
[Reviewed by Robohands]
Fixes #5386.
Problem
--color-syntax-punctuationborrowed--color-text-disabled, a token WCAG deliberately exempts from the normal-text contrast requirement because it marks an inactive control. Punctuation in a code sample is always-active, normal text.Measured every theme's punctuation/background pair (resolving
light-dark()/var()indirection, same approach as #4446's badge contrast guard). Three fail AA (4.5:1):butter, gothic, stone, and y2k already had their own passing punctuation colour and are untouched.
Fix
The shared default (used by any theme that doesn't define its own syntax palette) now points at
--color-text-secondaryinstead — already used for--color-syntax-comment, already verified to clear AA.The three failing themes each define their own syntax palette rather than inheriting the default, so each needed a dedicated fix:
#6e6e6e#a0a0a0#9e622e#cb884d#566a39#92af6aRegenerated the CLI theme template bundle (
pnpm bundle:cli-themes) soastryx theme addscaffolds the fixed values too.Verification
Added
scripts/check-syntax-punctuation-contrast.test.mjs: resolves every theme's punctuation/background pair the same way the badge guard does, and holds all seven to AA in both colour schemes. Confirmed it catches a real regression — reverted neutral's fix locally, ran the suite, watched it fail with the exact numbers from the issue (neutral/light — #a3a3a3 on #fafafa = 2.42:1), then restored it.Before (neutral theme, dark mode) — punctuation dims into the background:

After — clearly legible:

Typecheck and lint clean. Full
packages/themes+packages/core/src/themesuite passes (749/751 — the 2 failures aretheme/extensibleAxes.test.ts, a pre-existing, unrelated AST-scan failure I confirmed present on a cleanupstream/maincheckout before touching anything here).