Skip to content

Arbitrary values: Fix color() and light-dark() being classified as lengths - #712

Merged
dcastil merged 1 commit into
dcastil:mainfrom
ddussi:bugfix/color-function-length-detection
Sep 6, 2026
Merged

dcastil merged 1 commit into
dcastil:mainfrom
ddussi:bugfix/color-function-length-detection

Conversation

@ddussi

@ddussi ddussi commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Fixes #710

twMerge('text-sm text-[color(display-p3_1_0_0/50%)]') removes text-sm because the percentage inside the color is mistaken for a length. The same issue affects light-dark() and other prefixes shared by colors and lengths, including border and stroke utilities.

Add color and light-dark to the existing colorFunctionRegex exclusion used by isLengthOnly, following the treatment of color-mix() in #591. This preserves unrelated size utilities and correctly resolves color-to-color conflicts. The fix covers lowercase function names and retains the existing case-sensitive matching behavior.

Regression tests cover both class orders, text-color replacement, and preservation of font size, border width, and stroke width. Two documentation examples are included in the existing example test, and relevant testing guidance is updated.

Validation:

  • Against unmodified source: 4 failing tests across the color, validator, and documentation tests. With the fix: 34 test files / 122 tests pass with coverage.
  • pnpm lint, pnpm test:types, pnpm build, and pnpm test:exports pass, including TypeScript 3.8 declaration compatibility.
  • Changed TypeScript files pass the repository's Prettier configuration.
  • Verified generated color declarations with Tailwind 4.0.0, 4.1.17, 4.2.0, and 4.3.0.

@github-actions github-actions Bot added bug Something isn't working context-v3 Related to tailwind-merge v3 labels Sep 6, 2026

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

Looks good, thanks!

@codspeed

codspeed Bot commented Sep 6, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 7 untouched benchmarks


Comparing ddussi:bugfix/color-function-length-detection (f70c32f) with main (bceabfd)

Open in CodSpeed

@dcastil
dcastil merged commit 0e4856c into dcastil:main Sep 6, 2026
11 checks passed
@github-actions

github-actions Bot commented Sep 6, 2026

Copy link
Copy Markdown

This was addressed in release v3.6.0-dev.0e4856ca9f23c541650709ce27c6674c65d3dd1a.

@dcastil dcastil changed the title Fix color() and light-dark() being classified as lengths Arbitrary values: Fix color() and light-dark() being classified as lengths Sep 6, 2026
@github-actions

Copy link
Copy Markdown

This was addressed in release tailwind-merge@3.7.0.

desmondinho added a commit to desmondinho/tailwind-merge-dotnet that referenced this pull request Oct 11, 2026
* fix(validators): classify `color()` and `light-dark()` arbitrary values as colors

Arbitrary values using these functions with percentages were classified
as lengths instead of colors.

Ports dcastil/tailwind-merge#712 (v3.7.0).

* fix(config): bare `bg-conic` not merging with other background image classes

Ports dcastil/tailwind-merge#708 (v3.7.0).

* fix(config): `columns-auto` not conflicting with other `columns` classes

Ports dcastil/tailwind-merge#707 (v3.7.0).

* fix(config): container sizes like `inline-2xl` not merging

Adds the container theme scale to the inline size groups and points
the inline/block size groups to their own Tailwind docs pages.

Ports dcastil/tailwind-merge#706 (v3.7.0).

* fix(config): `max-h-none` missing in max-h class group

Ports dcastil/tailwind-merge#704 (v3.7.0).

* fix(config): axis shorthands like `px` not overriding logical sides like `ps`

Since Tailwind CSS v4 the axis utilities compile to logical shorthand
properties (px -> padding-inline), which fully override their
logical-side longhands (ps -> padding-inline-start). Applies to
padding, margin, inset, border width, border color, scroll margin and
scroll padding.

Ports dcastil/tailwind-merge#705 (v3.7.0).

* fix(config): `leading-none` being removed when the leading theme scale is overridden

Ports dcastil/tailwind-merge#689 (v3.7.0).

* fix(config): deprecated `shadow-inner` being classified as shadow color instead of shadow

Ports dcastil/tailwind-merge#703 (v3.7.0).

* fix(validators): arbitrary values using `color-mix()` not being detected as colors

Was missed when porting dcastil/tailwind-merge#591 (v3.3.1).

* fix(config): arbitrary variables not supported in background image classes

`bg-(image:--x)` / `bg-(url:--x)` were classified as background colors
and `bg-linear-(--x)`, `bg-radial-(--x)`, `bg-conic-(--x)` were not
recognized. Aligns the bg-image class group with upstream tailwind-merge,
where these have been supported since v3.0.0.

* fix(config): `lh` values missing in h, min-h and max-h class groups

Adds support for Tailwind CSS v4.1.5 `h-lh`, `min-h-lh` and `max-h-lh`
utilities.

Was missed when porting dcastil/tailwind-merge#575 (v3.3.0).

* style(config): move `auto` to the top of the columns class group

* style(config): move `containerTheme` after the strings in the inline sizing scale

* style(config): order arbitrary variable validators after arbitrary value validators in the bg-image class group

* fix(config): blur theme sizes like `blur-sm` not merging

The blur and backdrop-blur scales didn't use the blur theme and only
accepted arbitrary lengths, so `blur-sm blur-lg` wasn't merged and
arbitrary variables like `blur-(--x)` weren't recognized. Aligns the
scale with upstream tailwind-merge (since v3.0.0).

* fix(config): arbitrary variables like `z-(--x)` not supported in z-index classes

`V.IsInteger` was listed twice instead of `V.IsArbitraryVariable`.

* fix(config): non-length arbitrary values not supported in outline-offset classes

Values like `outline-offset-(--x)` or `outline-offset-[var(--x)]`
weren't recognized because only arbitrary lengths were accepted.
Aligns the group with upstream tailwind-merge (since v3.0.0).

* fix(config): arbitrary font-family and font-weight classes merging incorrectly

Unlabeled arbitrary values and variables in `font-*` classes are now
treated as font weights, and font families need the `family-name:`
label, matching Tailwind CSS. Adds the `IsArbitraryWeight`,
`IsArbitraryFamilyName` and `IsArbitraryVariableWeight` validators.

Was missed when porting dcastil/tailwind-merge#635 (v3.4.1).

* fix(validators): number validators accepting `NaN` and thousands separators and depending on the current culture

`IsNumber` accepted values like `NaN` and `1,000`, and `IsInteger`
parsed with the current culture, so `-1` wasn't an integer in cultures
like fa-IR or ar-SA. Both now parse invariantly like upstream
tailwind-merge's `Number()`-based checks, which also makes `IsInteger`
accept values like `1.0`, `1e3` and integers beyond the int range.

* test: port upstream wonky inputs tests

* test: port missing upstream test cases

* style(config): order `IsArbitraryWeight` before `IsArbitraryVariableWeight` in the font-weight class group
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

color() and light-dark() with percentages are mistaken for lengths

2 participants