From e231ea6c613344a8f8f578a271ba8ac66a2b3045 Mon Sep 17 00:00:00 2001 From: Brad Cornes Date: Tue, 1 Nov 2022 16:29:47 +0000 Subject: [PATCH] Fix merging of arrays during config resolution (#9706) * Fix merging of arrays during config resolution * Update changelog --- CHANGELOG.md | 1 + src/util/resolveConfig.js | 10 +++------- tests/resolveConfig.test.js | 6 ++++-- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 209022fba0c0..a9e5beea3ca8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/util/resolveConfig.js b/src/util/resolveConfig.js index 35b0cef5fe31..7e9deebe843c 100644 --- a/src/util/resolveConfig.js +++ b/src/util/resolveConfig.js @@ -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() @@ -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] @@ -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] } diff --git a/tests/resolveConfig.test.js b/tests/resolveConfig.test.js index 60776a39a88b..954c406597d8 100644 --- a/tests/resolveConfig.test.js +++ b/tests/resolveConfig.test.js @@ -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"' }], }, }, }, @@ -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"' }], }, }, })