Skip to content

fix: prevent arbitrary font-family and font-weight from merging#635

Merged
dcastil merged 12 commits intodcastil:mainfrom
roneymoon:font-validator-conflict
Jan 31, 2026
Merged

fix: prevent arbitrary font-family and font-weight from merging#635
dcastil merged 12 commits intodcastil:mainfrom
roneymoon:font-validator-conflict

Conversation

@roneymoon
Copy link

@roneymoon roneymoon commented Jan 27, 2026

What does this change do?

This PR fixes an issue where arbitrary font-family and font-weight utilities were incorrectly merged by tailwind-merge, causing one of them to be dropped when both were present.

The problem occurred because the font-weight class group was using an overly broad arbitrary validator, which also matched font-family values (e.g. family-name:). As a result, both utilities were classified into the same group and one would override the other.

This change makes the font-weight matching more precise so that each utility is correctly classified and both can safely coexist.


What was the issue?

Given the following input:

twMerge('font-(family-name:--custom-family) font-(--custom-weight)')

Before

'font-(--custom-weight)'

After

'font-(family-name:--custom-family) font-(--custom-weight)'

The same incorrect behavior happened regardless of class order.


How is this fixed?

  • Introduced weight-specific arbitrary validators that only match:

  • unlabeled variables intended for font weight (e.g. (--custom-weight))

  • explicitly labeled weight values (e.g. (weight:...), (number:...))

  • Replaced the generic isArbitraryVariable usage in the font-weight class group with these more specific validators

  • Left font-family logic unchanged so it continues to correctly handle family-name: and other family-related arbitrary values

  • This avoids the over-matching that caused both utilities to be treated as font-weight.


Why this approach?

  • Keeps the fix minimal and localized

  • Avoids changing validator execution order or introducing priorities

  • Does not modify configuration or public APIs

  • Preserves existing behavior while fixing the incorrect merge


Thanks for taking a look!

Closes #588

@github-actions github-actions bot added the context-v3 Related to tailwind-merge v3 label Jan 27, 2026
@codspeed-hq
Copy link

codspeed-hq bot commented Jan 31, 2026

Merging this PR will not alter performance

✅ 7 untouched benchmarks


Comparing roneymoon:font-validator-conflict (b232b67) with main (95ce92f)

Open in CodSpeed

Copy link
Owner

@dcastil dcastil left a comment

Choose a reason for hiding this comment

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

Hey @roneymoon! 👋

I expected a fix to be much more involved, awesome that you found a much simpler solution! Thanks for fixing the issue!

I fixed some additional minor nuances and added some tests and docs for the changes.

@dcastil dcastil merged commit a27cb4c into dcastil:main Jan 31, 2026
5 checks passed
@dcastil dcastil added the bug Something isn't working label Jan 31, 2026
@github-actions
Copy link

This was addressed in release v3.4.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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix arbitrary variables of font-family and font-weight groups being merged incorrectly

3 participants

Comments