Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix merging of arrays during config resolution #9706

Merged
merged 2 commits into from Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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