Skip to content

Tailwind config: Using closure to access theme function leads to invalid base style rule #7186

@edda

Description

@edda

What version of Tailwind CSS are you using?
v3.0.14

What browser are you using?
Chrome

What operating system are you using?
macOS

Reproduction URL
https://play.tailwindcss.com/adavrUyj2z?file=config

Describe your issue

When using a closure to access the theme function inside the backgroundColor section in the tailwind.config.js like so:

        theme: {  
          borderColor: ({theme}) => ({
            ...theme('colors'),
            danger: "#f00",
          }),
        }

or even without accessing theme:

        theme: {  
          borderColor: ({theme}) => ({
            danger: "#f00",
          }),
        }

the base style border-color (https://github.com/tailwindlabs/tailwindcss/blob/master/src/css/preflight.css#L12) comes out as:

        *, ::before, ::after {
          box-sizing: border-box;
          border-width: 0;
          border-style: solid;
          border-color: 'currentColor';
        }

wrong-color-2

which is ignored by the browser because it is an invalid value. Without the closure it is:

        *, ::before, ::after {
          box-sizing: border-box;
          border-width: 0;
          border-style: solid;
          border-color: currentColor;
        }

This is especially problematic if you minimize your CSS in the build step, because the minimization will turn the three separate border rules into a single rule:

   border: 0 solid 'currentColor';

wrong-color

The invalid color value makes the whole rule invalid which can lead to elements suddenly having borders even though you don't expect them to (this is how I found the issue ;)).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions