tailwindcss/packages
Robin Malfait 0c14df1a15
Fix resolving colors via theme(…) in compat mode with nested objects (#19097)
This PR fixes an issue when loading (nested) colors from a config file
and later referencing it via the `theme(…)` function in CSS.

Given a config like this:

```js
module.exports = {
  theme: {
    colors: {
      foo: 'var(--foo-foo)',
      'foo-bar': 'var(--foo-foo-bar)',
    },
  },
}
```

We internally map this into the design system. The issue here is that
the `foo` and `foo-bar` are overlapping and it behaves more like this:

```js
{
  foo: {
    DEFAULT: 'var(--foo-foo)',
    bar: 'var(--foo-foo-bar)'
  },
}
```

So while we can easily resolve `colors.foo-bar`, the `colors.foo` would
result in the object with a `DEFAULT` key. This PR solves that by using
the `DEFAULT` key if we end up with an object that has it.

If you end up resolving an object (`theme(colors)`) then the behavior is
unchanged.


## Test plan

1. Added a test based on the config in the issue (which failed before
this fix).
2. Also simplified the test case after identifying the problem (with the
`DEFAULT` key).

Fixes: #19091
2025-10-09 17:10:32 +00:00
..
@tailwindcss-browser Introduce canonicalizeCandidates on the internal Design System (#19059) 2025-10-07 12:41:12 +02:00
@tailwindcss-cli Prepare v4.1.14 release (#19037) 2025-10-01 11:48:02 -04:00
@tailwindcss-node Suppress warnings when using :deep, :slotted and :global (#19094) 2025-10-09 11:58:51 +02:00
@tailwindcss-postcss Prepare v4.1.14 release (#19037) 2025-10-01 11:48:02 -04:00
@tailwindcss-standalone Prepare v4.1.14 release (#19037) 2025-10-01 11:48:02 -04:00
@tailwindcss-upgrade Fix resolving colors via theme(…) in compat mode with nested objects (#19097) 2025-10-09 17:10:32 +00:00
@tailwindcss-vite Prepare v4.1.14 release (#19037) 2025-10-01 11:48:02 -04:00
internal-example-plugin Prefix internal modules with internal-* (#14074) 2024-07-29 10:58:07 -04:00
tailwindcss Fix resolving colors via theme(…) in compat mode with nested objects (#19097) 2025-10-09 17:10:32 +00:00
tsconfig.base.json Improve debug logs (#15303) 2024-12-11 15:27:20 +01:00