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

Svelte 5: :where is inconsequently applied across multiple selectors when using SCSS placeholder #10710

Closed
pooledge opened this issue Mar 5, 2024 · 4 comments
Labels

Comments

@pooledge
Copy link

pooledge commented Mar 5, 2024

Describe the bug

Creating a SCSS placeholder and applying it to multiple class selectors within scoped style block leads to every selector but the last to inherit the placeholder's property not directly but through the :where pseudo, see reproduction below.

Reproduction

  1. Create new SvelteKit Project using Svelte 5
  2. npm install -D sass as required
  3. Paste the following into ./src/routes/+page.svelte:
<div class="a">A</div>
<div class="b">B</div>
<div class="c">C</div>

<style lang="scss">
	%is-test {
		color: red;
	}
	.a {
		@extend %is-test;
	}
	.b {
		@extend %is-test;
	}
	.c {
		@extend %is-test;
	}
</style>

Expected outcome:

.a:where(.svelte-hswmqs),
.b:where(.svelte-hswmqs),
.c:where(.svelte-hswmqs) {
	color: red;
}

or

.a.svelte-hswmqs,
.b.svelte-hswmqs,
.c.svelte-hswmqs {
	color: red;
}

Actual outcome:

.c.svelte-hswmqs,
.b:where(.svelte-hswmqs),
.a:where(.svelte-hswmqs) {
	color: red;
}

Logs

No response

System Info

System:
    OS: macOS 12.7.3
    CPU: (10) arm64 Apple M1 Max
    Memory: 8.97 GB / 64.00 GB
    Shell: 5.8.1 - /bin/zsh
Binaries:
    Node: 18.16.0 - ~/.nvm/versions/node/v18.16.0/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v18.16.0/bin/yarn
    npm: 9.6.5 - ~/.nvm/versions/node/v18.16.0/bin/npm
    pnpm: 8.15.3 - ~/.nvm/versions/node/v18.16.0/bin/pnpm
    bun: 1.0.23 - ~/.bun/bin/bun
Browsers:
    Chrome: 122.0.6261.94
    Edge: 122.0.2365.63
    Safari: 17.3.1
npmPackages:
    @sveltejs/adapter-auto: ^3.0.0 => 3.1.1 
    @sveltejs/kit: ^2.0.0 => 2.5.2 
    @sveltejs/vite-plugin-svelte: ^3.0.0 => 3.0.2 
    svelte: ^5.0.0-next.1 => 5.0.0-next.71 
    vite: ^5.0.3 => 5.1.5

Severity

Blocking an upgrade

@pooledge pooledge added the bug label Mar 5, 2024
@pooledge pooledge changed the title SCSS placeholder is applied with :where on scoped classes SCSS placeholder is applied with :where on scoped classes Mar 5, 2024
@bluwy
Copy link
Member

bluwy commented Mar 6, 2024

I think this should be reported to https://github.com/sveltejs/svelte. If I manually preprocess the SCSS to CSS and paste that to the Svelte REPL, I can see that Svelte isn't correctly adding the scoped classes. I'll transfer this issue there.

@bluwy bluwy transferred this issue from sveltejs/vite-plugin-svelte Mar 6, 2024
@pooledge pooledge changed the title SCSS placeholder is applied with :where on scoped classes :where is inconsequently applied across multiple selectors when using SCSS placeholder Mar 6, 2024
@pooledge pooledge changed the title :where is inconsequently applied across multiple selectors when using SCSS placeholder Svelte 5: :where is inconsequently applied across multiple selectors when using SCSS placeholder Mar 7, 2024
@dummdidumm
Copy link
Member

Fixed by #10730

@pooledge
Copy link
Author

It looks like we are ditching :where().

<div>
	<span class="a">A</span>
	<span class="b">B</span>
	<span class="c">C</span>
</div>

<style lang="scss">
	%is-test {
		color: red;
	}
	div {
		.a {
			@extend %is-test;
		}
	}
	.b {
		@extend %is-test;
	}
	.c {
		@extend %is-test;
	}
</style>

The outcome here is:

.c.svelte-2znujd, .b.svelte-2znujd, div.svelte-2znujd .a:where(.svelte-2znujd) {
  color: red;
}

Is the redundancy for nesting selectors intended?

@dummdidumm
Copy link
Member

The :where is needed, else any a child would get matched, which would be wrong (imagine having a child component also having an a tag, which then would get matched when it shouldn't). The other .svelte-.. selectors aren't redundant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants