Skip to content

Order aggregated CSS by library, then module dependency - #600

Closed
davesnx wants to merge 2 commits into
generate-dependency-orderfrom
generate-library-order
Closed

davesnx wants to merge 2 commits into
generate-dependency-orderfrom
generate-library-order

Conversation

@davesnx

@davesnx davesnx commented Sep 18, 2026

Copy link
Copy Markdown
Owner

styled-ppx.generate now orders rules at two levels: libraries first, then modules inside each library. A library's rules come after the rules of every library it depends on, so a consumer library's override of a dependency's atom wins by construction instead of by directory name. Inside a library the module dependency order from the previous PR applies unchanged, now scoped to that library's files.

A file's library is the library key the PPX records in [@@@css.config] from dune's library-name cookie; a file without the key groups with its directory. Library edges are collapsed from module references: a reference X that the referrer's own library defines is a module edge; otherwise it points at the one other library defining X, or, for wrapped libraries referenced through their alias module, at the one library whose capitalized name is X. Both levels reuse the same Kahn sort, so the alphabetical tiebreak and the warn-and-continue cycle policy apply at both. --order source still bypasses everything.

$ styled-ppx.generate consumer/main.ml zlib/inner.ml   # main references Zlib.Inner.x
/* This file is generated by styled-ppx, do not edit manually */
.zlib-inner{color:green;}
.consumer-main{color:blue;}

Evidence at ada6aed:

  • New cram tests library-order, library-order-wrapped, library-order-fallback, library-order-cycle, library-order-source-flag; log-flags.t and order-dependency.t gain the per-library info lines; order-cycle.t changes because its two directories now form two groups, which is the resolution the test's own comment anticipated.
  • On the Ahrefs monorepo's 5,824 post-PPX files (pinned PPX, so directory fallback, 246 groups): identical 23,274-rule set, 4.4 s against 3.7 s for the flat order; Stack rules still precede Textarea.
  • demo/melange/public/styles.css regenerates with three rules moved and no property or value changed.
  • make format-check, make build, make test: all exit 0.

Review from library_edge_target and order_by_dependency in packages/generate/generate.ml. Not included: @layer emission, which follows as its own opt-in PR.

Risk: two-way door. A revert restores the flat module order. Until then, aggregations that mix several libraries see rules regroup by library; the winner-diff script from the previous PR lists which cascade ties flip.

@vercel

vercel Bot commented Sep 18, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
styled-ppx Ready Ready Preview Sep 23, 2026 6:41am UTC

Request Review

The PPX emits the key dune's cookie is named after (`library-name`,
since 90cf166 on the cookie branch), and the generator reads
`Css_extraction.config_library_key`. These fixtures still wrote
`("library", ...)`, which the generator ignored; they passed anyway
because each fixture keeps every library in its own directory, so the
directory fallback produced the same groups. With the real key the
tests exercise the library path they describe. Outputs are unchanged.
@davesnx

davesnx commented Sep 23, 2026

Copy link
Copy Markdown
Owner Author

Superseded by #616, which carries this branch's commits rebased onto main together with the rest of the CSS ordering work.

@davesnx davesnx closed this Sep 23, 2026

This branch was successfully deployed

1 active deployment
Preview — 7fa24bf0 Deployed Sep 23, 2026 by vercel[bot]
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.

1 participant