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

dark selector does not work correctly in @apply starting from version 3.3.0 #13037

Closed
GermanJablo opened this issue Feb 26, 2024 · 5 comments
Closed

Comments

@GermanJablo
Copy link

What version of Tailwind CSS are you using?: v3.3.0
What build tool (or framework if it abstracts the build tool) are you using?: postcss-cli 8.4.32, Next.js 13.4.19, webpack
What version of Node.js are you using?: v20
What browser are you using?: Chrome
What operating system are you using?: Windows

Reproduction URL:
https://play.tailwindcss.com/8lfHYybqfC

Describe your issue

In the repro you can see that in the latest version of tw v3 the scrollbar does not turn green in dark mode, while it does in v2.

There is a workaround if you use the .dark class:

  /* THIS DOES NOT WORK */
  ::-webkit-scrollbar-track { @apply bg-yellow-800 dark:bg-green-800; }
  ::-webkit-scrollbar-thumb { @apply bg-yellow-500 dark:bg-green-500; }
  ::-webkit-scrollbar-thumb:hover { @apply bg-yellow-600 dark:bg-green-600; }

  /* THIS DOES WORK */
  ::-webkit-scrollbar-track { @apply bg-yellow-800 }
  ::-webkit-scrollbar-thumb { @apply bg-yellow-500 }
  ::-webkit-scrollbar-thumb:hover { @apply bg-yellow-600 }
  .dark ::-webkit-scrollbar-track { @apply bg-green-800; }
  .dark ::-webkit-scrollbar-thumb { @apply bg-green-500; }
  .dark ::-webkit-scrollbar-thumb:hover { @apply bg-green-600; }

This should work with the first option as well.

This issue has already been reported in different discussions without a repro, or in similar issues that were linked to a specific framework.

According to the release article of v3.3 there should be no breaking changes. This is one though.

@adamwathan
Copy link
Member

Definitely a real bug, thanks for reporting! My gut is we can fix this by updating the class strategy implementation to work like the selector strategy implementation, where we put the & at the front:

  } else if (mode === 'class') {
-   addVariant('dark', `:is(${selector} &)`)
+   addVariant('dark', `&:is(${selector}, ${selector} *)`)
  }

By the looks of it, our internals will properly hoist out the pseudo-elements automatically if we move things around this way.

Will try to get this patched up this week 👍

@RaghavenderSingh
Copy link

@adamwathan i am interested can you assign it me

@elinoza
Copy link

elinoza commented Mar 22, 2024

I came across the same issue with my next project. I solved it by making these changes in tailwind.config.js: from darkMode: ["class", "[data-theme='dark']"], into darkMode: ["selector", "[data-theme='dark']"],
"The selector strategy replaced the class strategy in Tailwind CSS v3.4.1."

@thecrypticace
Copy link
Contributor

I've merged in the fix for this and am aiming to tag a patch release within the next few hours. I'll update this once it's out.

@thecrypticace
Copy link
Contributor

v3.4.2 has been released and both the CDN and Play have been updated. Your Play now works as expected!

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

5 participants