Empty styles-generic-layout CSS file is emitted and linked as a render-blocking stylesheet

Open
#2,087 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
55/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
css, javascript

Research direction

Start with components/outer-layout/utils.js, where stylesForComponents adds every CSS asset of an entry without checking size, and with the styles-generic-layout entry in rspack.config.js that splitChunks leaves empty. Reproduce by building and checking that out/ holds a 0-byte styles-generic-layout.<hash>.css. Done when that file is no longer emitted or linked, and pages still load 270.<hash>.css for the sidebar layout.

Written by the indexing model from the issue text.

Description

What information was incorrect, unhelpful, or incomplete?

The build emits an empty (0-byte) stylesheet, static/client/styles-generic-layout.<hash>.css, and pages using the generic layout still link it with fetchpriority="high", followed by a <script></script>, so browsers make a render-blocking request for an empty file.

Cause:

  • components/generic-layout/server.css only contains @import url("../layout/2-sidebars.css");.
  • rspack.config.js turns each components/*/server.css into a styles-<dir> entry, and splitChunks moves the shared 2-sidebars.css (also imported by components/curriculum/layout.css and components/reference-layout/server.css) into a shared chunk (270.<hash>.css).
  • The styles-generic-layout CSS chunk is left without modules, but is still emitted as an empty file and listed in the entrypoint's assets in stats.json.
  • stylesForComponents (components/outer-layout/utils.js) adds every CSS asset of the entry without checking its size.
What did you expect to see?

No empty stylesheet emitted or linked; pages only link 270.<hash>.css for the sidebar layout.

Do you have any supporting links, references, or citations?

Found while testing a new uploader for the test environment, which rejected the empty body (411 Length Required): https://github.com/mdn/dex/actions/runs/43436975451

Do you have anything more you want to share?

It is the only 0-byte file among the ~344k files in out/. Pages linking it include /en-US/mcp, /en-US/observatory/docs/faq, /en-US/observatory/docs/tests_and_scoring, /en-US/plus/docs/faq and /en-US/plus/docs/features/*.

Possible fixes:

  • Skip zero-size CSS assets in stylesForComponents, which also covers future components whose CSS is fully hoisted into a shared chunk.
  • Or avoid the empty entry, e.g. by not making generic-layout a style entry, or by moving the shared layout CSS into a named cache group.
Dominant language
JavaScript
Stars
242
Forks
66
Avg merge
1d 2m
Merged PRs (30d)
49

Getting set up

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.

More from mdn/fred

All issues in mdn/fred

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.