Skip to content

:global and :local do not work with CSS nesting #421

Description

@iansan5653

Description

Nested declarations in CSS combine with spaces, so I would expect the following to work:

.scopedClass {
  :global {
    .globalClass {...}
  }
}

In this case, I'd expect scopedClass to be hashed and globalClass to be left unchanged, because the selector should be equivalent to .scopedClass :global .globalClass (the selector-less block left over is debatable but it seems like the easiest approach):

.scopedClass_1t7w5_1 {
  {
    .globalClass {...}
  }
}

However, in practice, CSS Modules does not recognize the global scope for the nested class and hashes both scopedClass and globalClass:

.scopedClass_1t7w5_1 {
  {
    .globalClass_1t7w5_2 {...}
  }
}

Use-case

If this worked, it could be an extremely useful feature for working with UI from external libraries. I could apply a hashed container class around the entire component, then apply unhashed styles within the component, thus encapsulating my styling with no repetition. Take CodeMirror as an example:

.codeMirrorContainer :global {
  .cm-editor {...}

  .cm-line {...}

  .cm-placeholder {...}
}

To make this work currently, I have to repeat global for every selector:

.codeMirrorContainer {
  :global .cm-editor {...} /* or `:global(.cm-editor)` */

  :global .cm-line {...}

  :global .cm-placeholder {...}
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions