Repository: tailwindlabs/tailwindcss (TypeScript)

Issue:
arbitrary variants with modifiers inside the selector are generated in the wrong order
<!-- Please provide all of the information requested below. We're a small team and without all of this information it's not possible for us to help and your bug report will be closed. -->

**What version of Tailwind CSS are you using?**

v3.2.4

**What build tool (or framework if it abstracts the build tool) are you using?**

playground

**Reproduction URL**
https://play.tailwindcss.com/RWATzeVv1a

**Describe your issue**

This arbitrary variant `[&::-webkit-scrollbar-thumb:hover]:bg-green-500` is generated in the wrong order as  `&:hover::-webkit-scrollbar-thumb` but should be `&::-webkit-scrollbar-thumb:hover`.

When replacing the `::` with just one `:`, the generated order is correct (but the result obviously does not work anymore)


Hints:

Patch:
diff --git a/src/util/formatVariantSelector.js b/src/util/formatVariantSelector.js
--- a/src/util/formatVariantSelector.js
+++ b/src/util/formatVariantSelector.js
@@ -250,7 +250,18 @@ export function finalizeSelector(
 let pseudoElementsBC = [':before', ':after', ':first-line', ':first-letter']
 
 // These pseudo-elements _can_ be combined with other pseudo selectors AND the order does matter.
-let pseudoElementExceptions = ['::file-selector-button']
+let pseudoElementExceptions = [
+  '::file-selector-button',
+
+  // Webkit scroll bar pseudo elements can be combined with user-action pseudo classes
+  '::-webkit-scrollbar',
+  '::-webkit-scrollbar-button',
+  '::-webkit-scrollbar-thumb',
+  '::-webkit-scrollbar-track',
+  '::-webkit-scrollbar-track-piece',
+  '::-webkit-scrollbar-corner',
+  '::-webkit-resizer',
+]
 
 // This will make sure to move pseudo's to the correct spot (the end for
 // pseudo elements) because otherwise the selector will never work


Test patch:
diff --git a/tests/variants.test.js b/tests/variants.test.js
--- a/tests/variants.test.js
+++ b/tests/variants.test.js
@@ -1096,3 +1096,52 @@ test('variant functions returning arrays should output correct results when nest
     }
   `)
 })
+
+test.only('arbitrary variant selectors should not re-order scrollbar pseudo classes', async () => {
+  let config = {
+    content: [
+      {
+        raw: html`
+          <div class="[&::-webkit-scrollbar:hover]:underline" />
+          <div class="[&::-webkit-scrollbar-button:hover]:underline" />
+          <div class="[&::-webkit-scrollbar-thumb:hover]:underline" />
+          <div class="[&::-webkit-scrollbar-track:hover]:underline" />
+          <div class="[&::-webkit-scrollbar-track-piece:hover]:underline" />
+          <div class="[&::-webkit-scrollbar-corner:hover]:underline" />
+          <div class="[&::-webkit-resizer:hover]:underline" />
+        `,
+      },
+    ],
+    corePlugins: { preflight: false },
+  }
+
+  let input = css`
+    @tailwind utilities;
+  `
+
+  let result = await run(input, config)
+
+  expect(result.css).toMatchFormattedCss(css`
+    .\[\&\:\:-webkit-scrollbar\:hover\]\:underline::-webkit-scrollbar:hover {
+      text-decoration-line: underline;
+    }
+    .\[\&\:\:-webkit-scrollbar-button\:hover\]\:underline::-webkit-scrollbar-button:hover {
+      text-decoration-line: underline;
+    }
+    .\[\&\:\:-webkit-scrollbar-thumb\:hover\]\:underline::-webkit-scrollbar-thumb:hover {
+      text-decoration-line: underline;
+    }
+    .\[\&\:\:-webkit-scrollbar-track\:hover\]\:underline::-webkit-scrollbar-track:hover {
+      text-decoration-line: underline;
+    }
+    .\[\&\:\:-webkit-scrollbar-track-piece\:hover\]\:underline::-webkit-scrollbar-track-piece:hover {
+      text-decoration-line: underline;
+    }
+    .\[\&\:\:-webkit-scrollbar-corner\:hover\]\:underline::-webkit-scrollbar-corner:hover {
+      text-decoration-line: underline;
+    }
+    .\[\&\:\:-webkit-resizer\:hover\]\:underline::-webkit-resizer:hover {
+      text-decoration-line: underline;
+    }
+  `)
+})