svelte-preprocess icon indicating copy to clipboard operation
svelte-preprocess copied to clipboard

unexpected style when I use `:where` in global CSS

Open saadeghi opened this issue 4 years ago • 2 comments

Describe the bug When I add a PostCSS preprocessor to svletekit, below CSS code doesn't work anymore:

<style global>
.btn:where(.btn-primary,.btn-secondary){
  background-color: green;
}
</style>

To Reproduce

  1. Clone this: https://github.com/saadeghi/svelte-preprocess-postcss-bug
  2. npm install
  3. npm run dev
  4. now uncomment line 5 on svelte.config.js to disable the preprocess and npm run dev again to see expected style

Expected behavior

Expected CSS:

.btn:where(.btn-primary,.btn-secondary){
  background-color: green;
}

generated CSS:

.btn:where(.btn-primary),:global(.btn-secondary){
  background-color:green
}

Information about your project: https://github.com/saadeghi/svelte-preprocess-postcss-bug

saadeghi avatar Oct 22 '21 19:10 saadeghi

+1.

This actually causes problems more often than one might think since popular packages like the-new-css-reset use :where.

Minimal repro for such cases is:

<style lang="sass" global>
  @use 'the-new-css-reset/css/reset'
</style>

kissge avatar Jun 06 '22 12:06 kissge

The bug is located in this function: https://github.com/sveltejs/svelte-preprocess/blob/main/src/modules/globalifySelector.ts#L11

The Regex does not account for more modern :where, :not and :ìs selectors

ivanhofer avatar Nov 10 '22 12:11 ivanhofer