🐛 Fixed contrast_text_color returning incorrect text color for some light backgrounds - #29834
Conversation
fixes TryGhost#27797 Use YIQ luminance from Color(...).rgb() to decide black vs white for contrast; added regression tests for reported light colors.
WalkthroughThe pull request adds tests for black contrast text on three light backgrounds and white contrast text on a mid-tone background. It updates the workspace catalog to 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ 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 |
|
| Command | Status | Duration | Result |
|---|---|---|---|
nx run ghost:test:ci:integration |
✅ Succeeded | 2m 18s | View ↗ |
nx run @tryghost/admin:test:acceptance |
✅ Succeeded | 7m 15s | View ↗ |
nx run-many -t test:unit -p ghost,@tryghost/ada... |
✅ Succeeded | 6m 8s | View ↗ |
nx run ghost:test:integration |
✅ Succeeded | 3m 5s | View ↗ |
nx run ghost-monorepo:lint:boundaries |
✅ Succeeded | 23s | View ↗ |
nx run-many -t lint -p ghost-monorepo,ghost,@tr... |
✅ Succeeded | 3m 47s | View ↗ |
nx run ghost:test:legacy |
✅ Succeeded | 3m 2s | View ↗ |
nx run ghost-admin:test |
✅ Succeeded | 3m 30s | View ↗ |
Additional runs (9) |
✅ Succeeded | ... | View ↗ |
💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗
☁️ Nx Cloud last updated this comment at 2026-08-10 19:21:06 UTC
ref TryGhost#27797 Preserved the shared color utility's established threshold while correcting the blue-channel calculation.
fixes TryGhost#27797 Applied the upstream blue-channel correction centrally so Core, Admin and Koenig continue sharing one contrast implementation.
ref TryGhost#27797 The temporary @tryghost/color-utils patch only covered the CJS, ES, and TypeScript sources, leaving browser consumers and debugging metadata on the faulty blue-channel accessor. Including the generated UMD bundle and source maps keeps every shipped entry point consistent until the upstream package release is available.
ref TryGhost#27797 The temporary dependency patch only needs to correct the CJS and ES entry points used by Ghost, with the TypeScript source retained for readable package debugging. Excluding the unconsumed UMD bundle and generated source maps keeps the repository patch reviewable and reduces it from 538 KB to 1.7 KB without changing runtime coverage.
fixes TryGhost#27797 @tryghost/color-utils 0.2.20 contains the corrected RGB blue-channel calculation, allowing every Ghost surface to use the supported shared release instead of a temporary dependency patch.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #29834 +/- ##
==========================================
+ Coverage 75.40% 75.45% +0.04%
==========================================
Files 1606 1605 -1
Lines 140381 140484 +103
Branches 17389 17429 +40
==========================================
+ Hits 105860 106004 +144
+ Misses 33444 33432 -12
+ Partials 1077 1048 -29
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|

Summary
Fixes
{{contrast_text_color}}and every other Ghost consumer oftextColorForBackgroundColorreturning white for light colors such as#dacafe,#ffa5b1, and#a3e6ff.Root cause
@tryghost/color-utils@0.2.19used.b()in its YIQ calculation. That accessor is the Lab b-channel, not the RGB blue channel, so many colors were classified incorrectly.Changes
@tryghost/color-utilsto the corrected0.2.20release from Use .blue() instead of .b() in textColorForBackgroundColor SDK#1031.contrast_text_colordelegating to the shared color utility so Core, Admin, Ember Admin, and Koenig use the same implementation.Validation
pnpm install --frozen-lockfile@tryghost/color-utils@0.2.20pnpm exec vitest run test/unit/frontend/helpers/contrast-text-color.test.js test/unit/server/services/email-rendering/email-design.test.js— 75 tests passedpnpm nx run @tryghost/admin:buildpassed, including Ember Admin and Koenig dependenciesFixes #27797
Checklist