Skip to content

Svelte 5: Cannot use :global() with CSS nesting #10540

@Pronian

Description

@Pronian

Describe the bug

A compiler error is thrown when using a nested CSS selector with :global().
The nested version of div :global(.b) throws an error, whereas the non-nested version doesn't throw an error.

Reproduction

REPL link

Steps:

  1. Create a component with the following source code:
<div>
	<div class="a">Normal nesting works</div>
	<div class="b">Nesting with :global doesn't work</div>
	<div class="c">Non-nested selector with :global works</div>
</div>

<style>
	div {
		font-family: monospace;

		.a {
			color: blue;
		}

		:global(.b) {
			color: red;
		}
	}

	div :global(.c) {
		color: green;
	} 
</style>
  1. Attempt to compile the component and observe the error
  2. Optionally remove/comment the :global(.b) selector to confirm that it's causing the issue

Logs

TypeError: e.selectors is not iterable
    at eval ([email protected]:1:503253)

System Info

Svelte 5 Version: Next.60
Happens an all OS-es and in the REPL

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcssStuff related to Svelte's built-in CSS handling

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions