Skip to content

fix: Stop repeating the license header in every compiled stylesheet - #4906

Merged
pan-kot merged 1 commit into
cloudscape-design:mainfrom
TrevorBurnham:fix-license-headers-in-partials
Sep 2, 2026
Merged

fix: Stop repeating the license header in every compiled stylesheet#4906
pan-kot merged 1 commit into
cloudscape-design:mainfrom
TrevorBurnham:fix-license-headers-in-partials

Conversation

@TrevorBurnham

@TrevorBurnham TrevorBurnham commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes #4905.

Sass copies loud comments into the compiled CSS, so each partial's license header was emitted once per entry point that @uses it. Every published stylesheet carried a median of 34 copies, and 580 KB of the 2305 KB of CSS was the same four lines repeated.

The 91 partials under src/ now declare the header with Sass line comments, which the compiler strips. The styles.scss entry points keep the block comment, so every output file still carries one. .stylelintrc enforces the right form for each using the commentType option added in cloudscape-design/build-tools#75.

before after
CSS, raw 2305 KB 1745 KB (-24.3%)
CSS, gzipped 303 KB 298 KB (-1.8%)
license header bytes 580 KB (25.2%) 32 KB (1.8%)
headers, total 5400 297
headers per stylesheet, median 34 1
headers per stylesheet, max 51 5
stylesheets with more than one 152 48

The gzipped win is small because gzip already deduped the identical blocks. The win is in unminified bytes, which is what dev servers serve and what the internal package ships. Minified production bundles are unaffected either way, since minifiers strip the comments already.

Two things reviewers should know:

1. Every generated scoped class name changes. The name is awsui_{name}_{fileHash}_{contentHash}_{lineNumber}, and removing comments moves both the content hash and the line numbers. No snapshot needs updating, though: the test-utils selectors snapshot truncates to the path-derived hash, and since #4936, keyframe names derive from stable per-keyframe hashes rather than from a hash of src/internal/styles/global.scss, so the design tokens and themes snapshots no longer move with this change either. The compiled CSS is otherwise identical, verified as described below.

2. This does not remove every duplicate. 48 stylesheets still carry more than one header, up to 5. That remainder is a Dart Sass behaviour, not something this repo controls: an entry point's leading comments are re-emitted once per module when the entry point and its partials share a dependency. Minimal repro on Sass 1.89.2, no Cloudscape code involved:

// _shared.scss
.shared { color: gray; }
@mixin m { color: gray; }

// _a.scss     -> @use "shared";  .a { color: red; }
// _b.scss     -> @use "shared";  .b { color: blue; }

// entry.scss
/* ENTRY HEADER */
@use "shared";
@use "a";
@use "b";

ENTRY HEADER is emitted three times. This is the shape of every Cloudscape component that has sub-partials, which is why popover still ends up with several headers rather than one. It accounts for roughly 6 KB and is worth a follow-up upstream; it does not block this change.

The other source named in #4905, @cloudscape-design/component-toolkit, is already resolved: cloudscape-design/component-toolkit#248 converted its two SCSS files and shipped in 1.0.0-beta.182, which this branch builds against. That is why the median here reaches 1 rather than 2.

How has this been tested?

A normalised comparison of all 229 compiled stylesheets against a build of main from the same node_modules. After neutralising license blocks and the contentHash/lineNumber segments of scoped names, all 229 stylesheets are byte-identical. No file was added, removed, or left empty.

Review checklist

The following items are to be evaluated by the author(s) and the reviewer(s).

Correctness

  • Changes include appropriate documentation updates.
  • Changes are backward-compatible if not indicated, see CONTRIBUTING.md.
  • Changes do not include unsupported browser features, see CONTRIBUTING.md.
  • Changes were manually tested for accessibility, see accessibility guidelines.

Testing

  • Changes are covered with new/existing unit tests?
  • Changes are covered with new/existing integration tests?

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Comment thread .stylelintrc Outdated
@TrevorBurnham
TrevorBurnham force-pushed the fix-license-headers-in-partials branch 3 times, most recently from 70da272 to 5627044 Compare August 27, 2026 15:16
@TrevorBurnham
TrevorBurnham marked this pull request as ready for review August 27, 2026 15:19
@TrevorBurnham
TrevorBurnham requested a review from a team as a code owner August 27, 2026 15:19
@TrevorBurnham
TrevorBurnham requested review from jperals and pan-kot and removed request for a team August 27, 2026 15:19
pan-kot
pan-kot previously approved these changes Aug 27, 2026
@github-actions
github-actions Bot temporarily deployed to fork-dev-pages-react16 August 27, 2026 16:42 Inactive
@github-actions
github-actions Bot temporarily deployed to fork-dev-pages-react18 August 27, 2026 16:42 Inactive
@TrevorBurnham
TrevorBurnham force-pushed the fix-license-headers-in-partials branch from 5627044 to 555ee3e Compare August 27, 2026 17:03
@TrevorBurnham
TrevorBurnham requested a review from pan-kot August 27, 2026 17:22
jperals
jperals previously approved these changes Aug 28, 2026
@jperals
jperals enabled auto-merge August 28, 2026 08:09
@github-actions
github-actions Bot temporarily deployed to fork-dev-pages-react18 August 28, 2026 08:18 Inactive
@github-actions
github-actions Bot temporarily deployed to fork-dev-pages-react16 August 28, 2026 08:19 Inactive
pan-kot
pan-kot previously approved these changes Aug 28, 2026
Sass copies loud comments into the compiled CSS, so each partial's header
was emitted once per entry point that @uses it. Every published
stylesheet carried a median of 34 copies, and 580 KB of the 2304 KB of
CSS was the same four lines repeated.

Partials now declare the header with Sass line comments, which the
compiler strips. Entry points keep the block comment, so every output
file still carries one. Stylelint enforces the right form for each via
the commentType option from cloudscape-design/build-tools#75.

Published CSS drops from 2304 KB to 1743 KB, and the median number of
headers per stylesheet from 34 to 1. The 48 files that still carry more
than one hit a Sass behaviour that re-emits an entry point's leading
comments once per module when the entry and its partials share a
dependency, which is tracked in the issue.

The compiled CSS is otherwise byte-identical. Generated scoped class
names change because the name embeds a content hash and a line number,
and the design tokens snapshot changes because tokenStylesSuffix hashes
internal/styles/global.scss.

Refs cloudscape-design#4905.
auto-merge was automatically disabled September 1, 2026 14:18

Head branch was pushed to by a user without write access

@TrevorBurnham
TrevorBurnham dismissed stale reviews from pan-kot and jperals via 582c306 September 1, 2026 14:18
@TrevorBurnham
TrevorBurnham force-pushed the fix-license-headers-in-partials branch from 555ee3e to 582c306 Compare September 1, 2026 14:18
@codecov

codecov Bot commented Sep 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.75%. Comparing base (a420fd6) to head (582c306).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4906      +/-   ##
==========================================
- Coverage   97.66%   93.75%   -3.92%     
==========================================
  Files         959      958       -1     
  Lines       31342    27138    -4204     
  Branches    11577     9345    -2232     
==========================================
- Hits        30610    25443    -5167     
- Misses        725      790      +65     
- Partials        7      905     +898     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions
github-actions Bot temporarily deployed to fork-dev-pages-react18 September 2, 2026 08:24 Inactive
@github-actions
github-actions Bot temporarily deployed to fork-dev-pages-react16 September 2, 2026 08:24 Inactive
@jperals
jperals added this pull request to the merge queue Sep 2, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 2, 2026
@pan-kot
pan-kot added this pull request to the merge queue Sep 2, 2026
Merged via the queue into cloudscape-design:main with commit 6de850b Sep 2, 2026
53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Published CSS contains 30-50 duplicate license headers per file (26% of CSS bytes)

3 participants