Skip to content

Commit 6cf3e3e

Browse files
Don't mutate custom color palette when overriding per-plugin colors (#6546)
1 parent 4a5ba37 commit 6cf3e3e

File tree

3 files changed

+66
-2
lines changed

3 files changed

+66
-2
lines changed

CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10-
- Nothing yet!
10+
### Fixed
11+
12+
- Don't mutate custom color palette when overriding per-plugin colors ([#6546](https://github.com/tailwindlabs/tailwindcss/pull/6546))
1113

1214
## [3.0.6] - 2021-12-16
1315

src/util/resolveConfig.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import colors from '../public/colors'
66
import { defaults } from './defaults'
77
import { toPath } from './toPath'
88
import { normalizeConfig } from './normalizeConfig'
9+
import isPlainObject from './isPlainObject'
10+
import { cloneDeep } from './cloneDeep'
911

1012
function isFunction(input) {
1113
return typeof input === 'function'
@@ -144,7 +146,15 @@ function resolveFunctionKeys(object) {
144146
val = isFunction(val) ? val(resolvePath, configUtils) : val
145147
}
146148

147-
return val === undefined ? defaultValue : val
149+
if (val === undefined) {
150+
return defaultValue
151+
}
152+
153+
if (isPlainObject(val)) {
154+
return cloneDeep(val)
155+
}
156+
157+
return val
148158
}
149159

150160
resolvePath.theme = resolvePath

tests/basic-usage.test.js

+52
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,55 @@ test('all plugins are executed that match a candidate', () => {
5757
`)
5858
})
5959
})
60+
61+
test('per-plugin colors with the same key can differ when using a custom colors object', () => {
62+
let config = {
63+
content: [
64+
{
65+
raw: html`
66+
<div class="bg-theme text-theme">This should be green text on red background.</div>
67+
`,
68+
},
69+
],
70+
theme: {
71+
// colors & theme MUST be plain objects
72+
// If they're functions here the test passes regardless
73+
colors: {
74+
theme: {
75+
bg: 'red',
76+
text: 'green',
77+
},
78+
},
79+
extend: {
80+
textColor: {
81+
theme: {
82+
DEFAULT: 'green',
83+
},
84+
},
85+
backgroundColor: {
86+
theme: {
87+
DEFAULT: 'red',
88+
},
89+
},
90+
},
91+
},
92+
corePlugins: { preflight: false },
93+
}
94+
95+
let input = css`
96+
@tailwind utilities;
97+
`
98+
99+
return run(input, config).then((result) => {
100+
expect(result.css).toMatchFormattedCss(css`
101+
.bg-theme {
102+
--tw-bg-opacity: 1;
103+
background-color: rgb(255 0 0 / var(--tw-bg-opacity));
104+
}
105+
.text-theme {
106+
--tw-text-opacity: 1;
107+
color: rgb(0 128 0 / var(--tw-text-opacity));
108+
}
109+
`)
110+
})
111+
})

0 commit comments

Comments
 (0)