Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

An option to generate scoped styles using :where #554

Closed
brc-dd opened this issue Jul 26, 2023 · 6 comments
Closed

An option to generate scoped styles using :where #554

brc-dd opened this issue Jul 26, 2023 · 6 comments

Comments

@brc-dd
Copy link
Member

brc-dd commented Jul 26, 2023

What problem does this feature solve?

Currently styles are generated like this:

.className[data-v-hash] {
  color: green;
}

It would be better if there is some option that can generate styles like this:

.className:where([data-v-hash]) {
  color: green;
}

In the above output, the specificity of the selector is preserved.

What does the proposed API look like?

Some option at config level like:

// vite.config.ts

export default {
  plugins: [
    vue({
      style: {
        useWhereInAttributeSelectors: true // some better name probably
      }
    })
  ]
}
@kleinfreund
Copy link

If it this can work reliable in all cases, that would be a great idea.

I just want to point out that within the current major version of Vue, this should be an opt-in change as this could easily break existing applications that rely on that increased specificity (often unbeknownst to the developers).

@rocifier
Copy link

rocifier commented Aug 4, 2023

so basically allow :where() and :is()?

@baiwusanyu-c
Copy link
Member

baiwusanyu-c commented Aug 8, 2023

Seems to be supported in vuejs/core#8929

@brc-dd
Copy link
Member Author

brc-dd commented Aug 8, 2023

Ah, vuejs/core#8929 is a bit different. It still generates the scoped attribute like .foo[data-v-test].

So, if I have something like this:

image

In future, there might be a way to opt into style generation like this:

.foo:where([data-v-7ba5bd90]) {
    color: red;
}

However, I agree this might not be desirable in some cases, and it would be easier to just do it with a custom postcss plugin instead. IG this can likely be closed as not planned.

@kleinfreund
Copy link

kleinfreund commented Aug 8, 2023

This issue is not about supporting :is() and :where() in general. It’s about changing the Vue mechanism for scoped styles to compile scoped styles using :where() as outlined in the original post. Instead of selector[data-v-*], you would get selector:where([data-v-*]) (very much a simplified example). This has the advantage of not unnecessarily increasing the specificity of scoped styles through the introduction on the attribute selector part.

@baiwusanyu-c
Copy link
Member

Yes, these supports still require further consideration

@haoqunjiang haoqunjiang transferred this issue from vuejs/core Sep 1, 2023
@vuejs vuejs locked and limited conversation to collaborators Sep 1, 2023
@haoqunjiang haoqunjiang converted this issue into discussion #555 Sep 1, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Projects
None yet
Development

No branches or pull requests

4 participants