Skip to content

Commit

Permalink
Fix merging of arrays during config resolution (#9706)
Browse files Browse the repository at this point in the history
* Fix merging of arrays during config resolution

* Update changelog
  • Loading branch information
bradlc committed Nov 1, 2022
1 parent 661f58c commit e231ea6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Escape special characters in resolved content base paths ([#9650](https://github.com/tailwindlabs/tailwindcss/pull/9650))
- Don't reuse container for array returning variant functions ([#9644](https://github.com/tailwindlabs/tailwindcss/pull/9644))
- Exclude non-relevant selectors when generating rules with the important modifier ([#9677](https://github.com/tailwindlabs/tailwindcss/issues/9677))
- Fix merging of arrays during config resolution ([#9706](https://github.com/tailwindlabs/tailwindcss/issues/9706))

## [3.2.1] - 2022-10-21

Expand Down
10 changes: 3 additions & 7 deletions src/util/resolveConfig.js
Expand Up @@ -16,10 +16,6 @@ function isFunction(input) {
return typeof input === 'function'
}

function isObject(input) {
return typeof input === 'object' && input !== null
}

function mergeWith(target, ...sources) {
let customizer = sources.pop()

Expand All @@ -28,7 +24,7 @@ function mergeWith(target, ...sources) {
let merged = customizer(target[k], source[k])

if (merged === undefined) {
if (isObject(target[k]) && isObject(source[k])) {
if (isPlainObject(target[k]) && isPlainObject(source[k])) {
target[k] = mergeWith({}, target[k], source[k], customizer)
} else {
target[k] = source[k]
Expand Down Expand Up @@ -103,12 +99,12 @@ function mergeThemes(themes) {

function mergeExtensionCustomizer(merged, value) {
// When we have an array of objects, we do want to merge it
if (Array.isArray(merged) && isObject(merged[0])) {
if (Array.isArray(merged) && isPlainObject(merged[0])) {
return merged.concat(value)
}

// When the incoming value is an array, and the existing config is an object, prepend the existing object
if (Array.isArray(value) && isObject(value[0]) && isObject(merged)) {
if (Array.isArray(value) && isPlainObject(value[0]) && isPlainObject(merged)) {
return [merged, ...value]
}

Expand Down
6 changes: 4 additions & 2 deletions tests/resolveConfig.test.js
Expand Up @@ -591,6 +591,8 @@ test('theme values in the extend section are not deeply merged when they are sim
extend: {
fonts: {
sans: ['Comic Sans'],
serif: ['Papyrus', { fontFeatureSettings: '"cv11"' }],
mono: [['Lobster', 'Papyrus'], { fontFeatureSettings: '"cv11"' }],
},
},
},
Expand Down Expand Up @@ -619,8 +621,8 @@ test('theme values in the extend section are not deeply merged when they are sim
theme: {
fonts: {
sans: ['Comic Sans'],
serif: ['Constantia', 'Georgia', 'serif'],
mono: ['Menlo', 'Courier New', 'monospace'],
serif: ['Papyrus', { fontFeatureSettings: '"cv11"' }],
mono: [['Lobster', 'Papyrus'], { fontFeatureSettings: '"cv11"' }],
},
},
})
Expand Down

0 comments on commit e231ea6

Please sign in to comment.