SharePoint / SharePoint/sp-dev-docs

CSS build pipeline broken with modern CSS and layered styles.

Open
#8,725 7 comments 0 reactions 1 assignee View on GitHub

@Ashlesha-MSFT is already working on this.

Since Nov 4, 2025.

area:spfx Needs: Author Feedback status:to-be-reviewed type:archive-old-issue type:bug-suspected
Dominant language
PowerShell
Stars
1.4k
Forks
1.1k
Avg merge
4d 12h
Merged PRs (30d)
12

Description

Target SharePoint environment

SharePoint Online

What SharePoint development model, framework, SDK or API is this about?

💥 SharePoint Framework

Developer environment

macOS

What browser(s) / client(s) have you tested
  • 💥 Internet Explorer
  • 💥 Microsoft Edge
  • 💥 Google Chrome
  • 💥 FireFox
  • 💥 Safari
  • mobile (iOS/iPadOS)
  • mobile (Android)
  • not applicable
  • other (enter in the "Additional environment details" area below)
Additional environment details

SPFx version: 1.16.1

Describe the bug / error

CSS file gets truncated with the following code it:

.mylayer {
  max-width: 80ch;
  margin: 2rem auto;
  font-size: 1.25rem;
  box-sizing: border-box;
  padding: 1rem;
}

@layer red,green;

@layer red {
  .mylayer {
    border: 1px red solid;
    color: red;
    padding: 2rem;
  }
}

@layer green {
  .mylayer {
    border: 1px green solid;
    color: green;
    padding: 3rem;
  }
}

The CSS code is not the problem but instead of having the same style in the outputted CSS the following is the result.

.mylayer{max-width:80ch;margin:2rem auto;font-size:1.25rem;box-sizing:border-box;padding:1rem}@layer red,green;
@layer red{color:red;padding:2rem}

So there must be some false treatment in the build chain because the green layer will not come through. CSS doesn't get applied to the web part too, so there must be an issue with loading the styles to the page.

Here is a working CSS Sample:
https://codepen.io/StfBauer/pen/wvxjJap

Steps to reproduce
  1. Create a web part with the version 1.16.1
  2. add the style sheet code in the SCSS File.
  3. add the following code to the web part.
  public render(): void {    
    this.domElement.innerHTML = `<div class="${styles.mylayer}">Lorem, ipsum dolor sit amet consectetur adipisicing elit. Odit assumenda deserunt culpa dolore provident cupiditate suscipit. Laboriosam non laborum dolorem necessitatibus quo! Perferendis nemo natus mollitia deserunt ex deleniti tempora.</div>`;
  }

Run the web part and check the lib folder to see if the same CSS was generated as the origin.

Expected behavior

Input CSS = Output CSS and leave my CSS alone.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.