Skip to content

fix(theme): give syntax punctuation its own AA-passing colour - #5414

Merged
cixzhang merged 2 commits into
meta:mainfrom
HelloOjasMutreja:fix/syntax-punctuation-contrast
Aug 24, 2026
Merged

cixzhang merged 2 commits into
meta:mainfrom
HelloOjasMutreja:fix/syntax-punctuation-contrast

Conversation

@HelloOjasMutreja

Copy link
Copy Markdown
Contributor

Fixes #5386.

Problem

--color-syntax-punctuation borrowed --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):

theme light dark
neutral 2.42:1 2.53:1
chocolate 3.06:1 2.56:1
matcha 3.83:1 2.73: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-secondary instead — 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:

theme new light new dark new ratios
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

Regenerated the CLI theme template bundle (pnpm bundle:cli-themes) so astryx theme add scaffolds 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:
before

After — clearly legible:
after

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

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

vercel Bot commented Aug 24, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
astryx Error Error Aug 24, 2026 1:04pm

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 24, 2026
@github-actions github-actions Bot added community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge needs:design-review Affects visuals — Design should review labels Aug 24, 2026
@github-actions

github-actions Bot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

🧪 Sandbox Preview

View Sandbox for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

No new or modified components detected.

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.8KB 1.2KB

Accessibility Audit

Status: No accessibility violations detected.


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

github-actions Bot added a commit that referenced this pull request Aug 24, 2026
@HelloOjasMutreja
HelloOjasMutreja marked this pull request as ready for review August 24, 2026 11:15
@gonzoblasco

Copy link
Copy Markdown
Contributor

Hi @HelloOjasMutreja, nice catch - --color-syntax-punctuation inheriting a WCAG-exempt disabled token for always-active text is exactly the class of bug that slips through. The measurement (resolving light-dark()/var() the same way the badge guard does) and the regression test are solid.

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.
The new default points --color-syntax-punctuation at --color-text-secondary, which is the same token --color-syntax-comment already uses. For the themes that inherit the default (butter, gothic, stone, y2k), punctuation now renders in the exact same colour as comments. That's a semantic distinction the syntax highlighter used to preserve (dim grey for punctuation vs something else for comments), and it's lost in one move. It clears AA, so it's not a correctness issue - but it's a visual-regression concern worth a deliberate decision: either confirm punctuation-as-comment-colour is intended for those themes, or give punctuation its own token so the two roles stay distinguishable. Worth checking against the before/after in those four themes, since they weren't part of the measured three.

2. The resolver only handles hex - it's worth failing loud when it can't resolve.
resolve() returns null for anything that isn't #rgb/#rrggbb/#rrggbbaa. Today every theme ships hex so the pairs all resolve, and the expect(rows).toHaveLength(14) guard catches a theme that stops resolving - but the failure message just says "expected 14, got 12" with no hint of which theme or why. If a future theme defines a colour in oklch()/hsl()/rgb(), the guard trips without telling anyone the resolver doesn't understand the format. A one-line throw (or a descriptive assertion) in resolve() when it hits an unsupported format would make the next person's debugging much faster. Same spirit as the "guards the resolver itself" test you already wrote - just one step more explicit.

Minor: consider reusing the badge guard's resolver instead of a second copy in scripts/, so the light-dark()/var() indirection logic has a single home. If the badge and syntax guards drift, one will silently cover a format the other doesn't.

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

Copy link
Copy Markdown
Contributor Author

Thanks for the independent WCAG verification, and for catching the resolver's silent-null gap.

On #2 (fail loud): pushed in 1c20165. resolve() now throws with the actual unresolvable value instead of falling through to null when it hits something that isn't hex/light-dark()/var(). Confirmed it's a no-op for current behavior — reran the suite, all 7 themes still resolve cleanly.

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 defineSyntaxTheme with their own full 14-token palette, and defineTheme.ts only writes --color-syntax-* from a theme's own syntax.tokens when input.syntax is provided (defineTheme.ts:632, if (input.syntax) { ... }) — there's no fallback path to syntaxTokenDefaults for a theme that has one. domainTokens/index.ts's own header calls syntaxTokenDefaults out as "used by defineTheme for validation + autocomplete," not a runtime CSS source.

So for the four you flagged, checking each theme file directly:

  • butter: comment: ['#605f52', '#adac9e'], punctuation: ['#605f52', '#adac9e'] — already identical, pre-existing, untouched by this PR.
  • stone: same pattern, ['#5e5e5e', '#ababb0'] for both — pre-existing, untouched.
  • y2k: same pattern, ['#5e5e5e', '#ababab'] for both — pre-existing, untouched.
  • gothic: comment: '#6b7079', punctuation: '#7a8290' — distinct, untouched.

The shared default I changed (--color-text-disabled → --color-text-secondary) only matters for a third-party theme that skips syntax: entirely, which none of the seven shipped ones do. Let me know if I'm missing a path where it does reach a shipped theme — happy to dig further if so, but I couldn't find one.

On the "share the resolver" note: agreed it's the right shape long-term, holding off on it here since it'd mean touching check-badge-contrast.test.mjs too, which is unrelated to this fix — happy to do it as a follow-up if you'd rather see it split out.

@gonzoblasco

Copy link
Copy Markdown
Contributor

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 syntax.tokens palette via defineSyntaxTheme, and defineTheme.ts only writes --color-syntax-* from a theme's own tokens when input.syntax is present - so syntaxTokenDefaults never reaches a shipped theme at runtime.

And confirming the specific values makes it conclusive: butter/stone/y2k already had punctuation === comment (pre-existing, untouched by this PR), and gothic has them distinct. So there's no visual regression introduced here - my point #1 is withdrawn. The default change only affects a third-party theme that skips syntax: entirely, which is a reasonable (and strictly better, since it now clears AA) behaviour for that case.

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.

github-actions Bot added a commit that referenced this pull request Aug 24, 2026

@cixzhang cixzhang 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 — 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]

@cixzhang
cixzhang enabled auto-merge (squash) August 24, 2026 18:35
@github-actions github-actions Bot removed the needs:code-review High-risk change (new package/component/API) — needs human code review before merge label Aug 24, 2026
@cixzhang
cixzhang merged commit 8707031 into meta:main Aug 24, 2026
20 of 21 checks passed

This branch had an error being deployed

1 failed deployment
Preview — 1c20165b Deployed Aug 24, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. community Authored by a community contributor (not on the eng/design team) needs:design-review Affects visuals — Design should review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Syntax punctuation fails WCAG AA contrast (2.42:1) — --color-syntax-punctuation borrows the disabled-text grey

3 participants