Skip to content

Don't add default config multiple times when presets are used #6567

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/util/getAllConfigs.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import defaultConfig from '../../stubs/defaultConfig.stub.js'
import { flagEnabled } from '../featureFlags'

export default function getAllConfigs(config) {
const configs = (config?.presets ?? [defaultConfig])
export default function getAllConfigs(config, depth = 0) {
const presets = config?.presets ?? (depth > 0 ? [] : [defaultConfig])
const configs = presets
.slice()
.reverse()
.flatMap((preset) => getAllConfigs(preset instanceof Function ? preset() : preset))
.flatMap((preset) => getAllConfigs(preset instanceof Function ? preset() : preset, depth + 1))

const features = {
// Add experimental configs here...
Expand Down
38 changes: 38 additions & 0 deletions tests/customConfig.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,3 +384,41 @@ test('function presets can be mixed with object presets', () => {
`)
})
})

test('Using presets without an empty presets array doesnt overwrite plugins', () => {
let plugin = require('../plugin')

let config = {
presets: [
require('../stubs/defaultConfig.stub.js'),
{
theme: {},
plugins: [
plugin(
function ({ matchUtilities, theme }) {
matchUtilities(
{ 'aspect-w': (value) => [{ color: value }] },
{ values: theme('aspectRatio') }
)
},
{
theme: { aspectRatio: { foo: 'red' } },
}
),
],
},
{
theme: { colors: {} },
},
],
content: [{ raw: `<div class="aspect-w-foo"></div>` }],
}

return run('@tailwind utilities', config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
.aspect-w-foo {
color: red;
}
`)
})
})