Skip to content

fix: recognize contrast-color and device-cmyk as colors - #729

Merged
dcastil merged 2 commits into
dcastil:mainfrom
Don-Yin:fix/contrast-color-device-cmyk
Nov 17, 2026
Merged

dcastil merged 2 commits into
dcastil:mainfrom
Don-Yin:fix/contrast-color-device-cmyk

Conversation

@Don-Yin

@Don-Yin Don-Yin commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Summary

I noticed that percentages inside contrast-color() and device-cmyk() are treated as lengths. This can remove an unrelated font-size class:

twMerge('text-[12px] text-[contrast-color(hsl(0_0%_0%))]')
// Before: 'text-[contrast-color(hsl(0_0%_0%))]'
// After:  'text-[12px] text-[contrast-color(hsl(0_0%_0%))]'

This adds both functions to the existing color-function exclusion in the length validator. The tests cover font-size, border-width, stroke-width, and text-color replacement in both orders, with two checked documentation examples. Tailwind CSS 4.3.3 generates separate font-size and color declarations for the reproduction.

Evidence

The same eight merge cases per function fail before the change and pass afterward. The figure shows case counts, not a performance benchmark.

Correct merge cases before and after the fix

Measured inputs and outputs: before, after.

Validation

  • pnpm --filter tailwind-merge test tests/colors.test.ts tests/validators.test.ts tests/docs-examples.test.ts. 31 passed. Before the fix, the color and validator files had 3 failed / 27 passed tests.
  • pnpm test. 648 passed across 78 files, including the Vite and Next.js integration tests.
  • pnpm lint
  • pnpm test:types
  • pnpm --filter tailwind-merge build
  • pnpm --filter tailwind-merge test:exports
  • pnpm exec prettier --check on the five changed files.

All commands passed. The full test run reported the existing locked-version mismatch between Vitest 4.1.11 and its coverage provider 4.1.10; no dependencies were changed.

@github-actions github-actions Bot added context-v3 Related to tailwind-merge v3 bug Something isn't working labels Oct 22, 2026
@Don-Yin

Don-Yin commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

Hi @dcastil, just a gentle ping on this one and #730 whenever you have time. No rush, and happy to change anything.

Don-Yin and others added 2 commits November 17, 2026 23:58
Exclude both functions from arbitrary length detection so percentages do
not remove unrelated font sizes, border widths, or stroke widths.
Add regression coverage for both class orders and document the behavior.

Signed-off-by: Don Yin <Don_Yin@outlook.com>
…res page

The tests in `colors.test.ts` and `validators.test.ts` already cover both functions, and the features page doesn't need an example for every color function, so the two examples and the matching docs example count go back to what main has.

Since the rebase, mask stops share `colorFunctionRegex` as well, so `contrast-color()` and `device-cmyk()` now count as colors there too. Tailwind puts them into the mask position variable instead, which only produces a broken gradient, so the agent notes record this as an accepted difference rather than keeping a mask-specific color list.
@dcastil
dcastil force-pushed the fix/contrast-color-device-cmyk branch from 773dcb1 to 70b0e09 Compare November 17, 2026 23:00
@codspeed

codspeed Bot commented Nov 17, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning

⚠️ Upgrade your CodSpeed plugin for Node.js 24

@codspeed/* 5.7.1 is only tested on Node.js 18, 20, and 22, so your Node.js 24 measurements may be inaccurate. Upgrade your @codspeed/* packages to 6.0.0 or later.

See affected benchmarks

βœ… 7 untouched benchmarks
⏩ 7 skipped benchmarks1


Comparing Don-Yin:fix/contrast-color-device-cmyk (70b0e09) with main (acff831)

Open in CodSpeed

Footnotes

  1. 7 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@dcastil dcastil left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Hey @Don-Yin! πŸ‘‹

Thanks for the improvement and sorry for the long wait! Looks good to me. I rebased your branch due to conflicts and removed the example from features.md since it's a bit too niche to include in the human docs.

@dcastil
dcastil merged commit 61f8790 into dcastil:main Nov 17, 2026
9 checks passed
@github-actions

Copy link
Copy Markdown

This was addressed in release tailwind-merge@3.7.0-dev.61f8790d2e377c5013a4e23947d2aeaedd7adbd5.

@github-actions

Copy link
Copy Markdown

This was addressed in release tailwind-merge@3.7.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working context-v3 Related to tailwind-merge v3 tailwind-merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants