Skip to content

:global selector in css nesting #10721

@FrancoJavierGadea

Description

@FrancoJavierGadea

Astro Info

Astro                    v4.5.16
Node                     v20.11.0
System                   Windows (x64)
Package Manager          npm
Output                   static
Adapter                  none
Integrations             @astrojs/react

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

This examples work fine

.container {

    & :global(h1) {

        color: #fff;
    }
}

/*Output css*/
.container[data-astro-cid-j7pv25f6] {
    & h1 {
        color: #fff;
    }
}
.container {

    & :global(h1) {
        color: #fff;
    }

    span {}
}

/*Output css*/
.container[data-astro-cid-j7pv25f6] {

    & h1 {
        color: #fff
    }

    span {}
}

This examples not work

.container {

    :global(h1) {

        color: #fff;
    }
}

/*Output css*/
.container[data-astro-cid-j7pv25f6] {
    :global(h1) {
        color: #fff;
    }
}
.container {

    span {}

    & :global(h1) {

        color: #fff;
    }
}

/*Output css*/
.container[data-astro-cid-j7pv25f6] {
    span {}

    & :global(h1) {
        color: #fff;
    }
}

What's the expected result?

.container {

    :global(h1) {

        color: #fff;
    }
}

/*Output css*/
.container[data-astro-cid-j7pv25f6] {
    h1 {
        color: #fff;
    }
}
.container {

    span {}

    & :global(h1) {

        color: #fff;
    }
}

/*Output css*/
.container[data-astro-cid-j7pv25f6] {
    span {}

    & h1 {
        color: #fff;
    }
}

Link to Minimal Reproducible Example

https://stackblitz.com/edit/withastro-astro-8wzk1y?file=src%2Fpages%2Findex.astro

Participation

  • I am willing to submit a pull request for this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    - P2: has workaroundAn edge case that only affects very specific usage, but has a trivial workaround (priority)pkg: astroRelated to the core `astro` package (scope)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions