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

Hover background color for button not working in production build when value is passed as a template literal #2209

Closed
mattalco opened this issue Aug 20, 2020 · 1 comment

Comments

@mattalco
Copy link

Describe the problem:

I have created a banner component in a personal project that contains a button. I pass in variable values for the button's background color, background color on hover, and text color. In a production build, I've noticed the hover color does not work - hovering has no effect on the background color.

Without knowing much about tailwind's internal CSS process, it would appear some optimization or tree-shaking is removing the necessary hover styles (but non-hover seems to work ok). I am lead to this because changing the color red in this example to blue where it's used elsewhere doesn't reproduce the issue.

Link to a minimal reproduction:

I used the tailwind blog code as the base for this reproduction. You can find the repo here: https://github.com/mattalco/tailwind_bug

On the main page, you will see several large buttons near the top. In dev mode, the red button will activate the hover state correctly. In a production build, it will not.

@adamwathan
Copy link
Member

You can't use interpolation to generate classes or PurgeCSS will fail to find the class, like you're experiencing:

https://github.com/mattalco/tailwind_bug/blob/master/src/components/Button.js#L5

Relevant documentation here:

https://tailwindcss.com/docs/controlling-file-size#writing-purgeable-html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants