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

Not detecting class names with template literals #6559

Closed
harryzcy opened this issue Dec 16, 2021 · 3 comments · Fixed by #6593
Closed

Not detecting class names with template literals #6559

harryzcy opened this issue Dec 16, 2021 · 3 comments · Fixed by #6593

Comments

@harryzcy
Copy link

What version of Tailwind CSS are you using?

v3.0.5

What build tool (or framework if it abstracts the build tool) are you using?

Vite 2.7.2 8.3.1, postcss 8.4.5, autoprefixer 10.4.0

What version of Node.js are you using?

v16.13.0

What browser are you using?

Chrome

What operating system are you using?

macOS

Describe your issue

When class names are contained in template literal strings, they are not picked up by the parser unless a trailing space is supplied. The template literals are common when using frameworks like React.

In the following example, 'overflow-scroll' is not picked up:

<div className={`overflow-scroll${conditionIsOpen ? '' : ' hidden'}`}></div>

This workaround works:

<div className={`overflow-scroll ${conditionIsOpen ? '' : ' hidden'}`}></div>

But it will result in an extra space between class names.

@u3u
Copy link

u3u commented Dec 16, 2021

Maybe it's a related issue, there's a similar issue in Vue JSX

// Not working
<div class={['w-[92%] max-w-[650px] mx-auto']}></div>
<div class={clsx(['w-[92%] max-w-[650px] mx-auto'])}></div>

// Working
<div class="w-[92%] max-w-[650px] mx-auto"></div>

Two days ago tried to upgrade to v3, because of this problem had to go back to v2

@lukewarlow
Copy link
Contributor

lukewarlow commented Dec 16, 2021

I'm not 100% sure but a fix at least for the first issue could be a change to the below regex (from line 24 of expandTailwindAtRules.js)

Current:

const INNER_MATCH_GLOBAL_REGEXP = /[^<>"'`\s.(){}[\]#=%]*[^<>"'`\s.(){}[\]#=%:]/g

Proposed:

const INNER_MATCH_GLOBAL_REGEXP = /[^<>"'`\s.(){}[\]#=%$]*[^<>"'`\s.(){}[\]#=%$:]/g

As I say I'm not actually sure if it's that block of code that's got the parsing issue with regards to template strings, but changing the regex does seem to match more properly in RegExr.

Though that wouldn't explain the Vue JSX issue above.

@RobinMalfait
Copy link
Contributor

Hey! Thank you for your bug report!
Much appreciated! 🙏

The issue will be fixed in #6593 and will be available in the next release.

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

Successfully merging a pull request may close this issue.

4 participants