question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Arbitrary variant selector syntax not working

See original GitHub issue

Hi, thank you for your work on UnoCSS. I am working with Solid and I am trying to use UnoCSS’s arbitrary selector feature which works in the playground.

Given the following code:

function App() {
  return <>
    <div class="[color:red]">Hello, world!</div>
    <div class="[&>*]:[color:red]">
      <div>Hello, world!</div>
      <div>Hello, world!</div>
      <div>Hello, world!</div>
      <div>Hello, world!</div>
    </div>
  </>
}

I expected all lines to be red but I’m only seeing the first line render as red.

Here’s a MVP repro: https://github.com/zaydek/solid-unocss-arbitrary-variant-bug.

Here is the playground version using the same code and config (I originally copied the config from the playground): https://uno.antfu.me/play/?html=DwEwlgbgBAxgNgQwM5ILwCIDaMD2ccBOAXAQKYgC66AfABKlz4A0UA7oXCAITAD04EagChQkWIhQZMAMmoAqCkWx5CJclWFQoowfUY4W7Apx79Im7QLoNmbDtz5WhWndf2H7ppy6t7bRk0dzETNBIA&config=JYWwDg9gTgLgBAbwFBzgEwKYDNgDsMDCEuOA5gDQpxhQYDOGMAqrhJQL5xZQQhwDkAV1YBjOnX5IkGAB6RY6bAENBAG3iYc%2BIiWCkAFMlQ16jOgC44AbSrHaDZq30BKSqgC6Sds6RA&options=N4IgLgTghgdgzgMwPYQLYgFwKgGzgUwF8g.

Is there something I’m doing wrong? Thank you.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
zaydekcommented, Aug 21, 2022

Alright I’m gonna close this issue since this is working. If future Solid users run into this, you can simply use:

import { defineConfig } from "vite"
import solid from "vite-plugin-solid"
import unocss from "unocss/vite"

export default defineConfig({
  plugins: [
    unocss(),
    solid(),
  ],
  server: {
    port: 3000,
  },
  build: {
    target: "esnext",
  },
})

Thanks @chris-zhu!

0reactions
zaydekcommented, Aug 20, 2022

@chris-zhu It looks like it’s the order of the plugins. By calling { ...solidPlugin(), enforce: "post" } it works. I did try to repro the repo you linked but I got the same results until I used enforce. I also tried pre on UnoCSS but got the error linked here: https://github.com/solidjs/solid/issues/1169#issuecomment-1221322246.

export default defineConfig({
  plugins: [
    {
      ...solidPlugin(),
      enforce: "post",
    },
    // ...
  ],
  // ...
})

Is there any foreseeable problem using enforce to get plugins to work together? Thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Feature Proposal] Support for arbitrary selector (variant) #6630
I would like to suggest a feature to support an arbitrary selector. It can come in handy in cases where we don't have...
Read more >
Configuring Variants - Tailwind CSS
Responsive variants are grouped together and inserted at the end of your stylesheet by default to avoid specificity issues, regardless of where responsive ......
Read more >
Attribute selectors - CSS: Cascading Style Sheets | MDN
Represents elements with an attribute name of attr whose value is a whitespace-separated list of words, one of which is exactly value.
Read more >
6 Selectors
CSS2 allows authors to use the class selector syntax (a "." followed by a class value) for arbitrary attributes, instead of for "class"....
Read more >
How to access all the direct children of a div in tailwindcss?
In tailwind 3.1, you can use arbitrary values to target child elements. <div class="[&>*]:p-4">...</div> <div class="[&>p]:mt-0 ">...</div>.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found