Skip to content

feat(styles): Tailwind content from an app's import graph, and the stylesheet inside each page CU-17tkuw617h7 - #2855

Merged
michaelassraf merged 10 commits into
mainfrom
refactor/per-page-css
Oct 29, 2026
Merged

michaelassraf merged 10 commits into
mainfrom
refactor/per-page-css

Conversation

@michaelassraf

@michaelassraf michaelassraf commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

What

@flamingo-stack/openframe-frontend-core/style-sources exports appStyleSources: the files an App Router app's served routes import (its own and this library's per-module ESM build, tree-shaken like the app's bundle), for Tailwind's content. Consumers stop listing this library's whole dist, which put every component's classes in the stylesheet every page blocks on (on the hub, ~299 KB of a 366 KB sheet).

  • routes asks the app which routes the build serves (a dynamic route counts when its static prefix is served).
  • firstPaint: true leaves the lazily loaded chat panel (LAZY_STYLED) out of the page's sheet.
  • EmbeddableChat gains loadStyles, called once when the chat's module starts loading, so a host loads its full stylesheet with the chat.
  • esbuild moves from devDependencies to dependencies: consumers run the scan.
  • README's Tailwind setup now uses it.

Tests

  • src/__tests__/style-sources.test.ts: route rules and an end-to-end walk on a fixture app.
  • embeddable-chat-loading.test.tsx: loadStyles runs when, and only when, the chat loads.

Measured (hub, consuming this through yalc)

before after
flamingo, CSS every page blocks on 374 KB 286 KB
openmsp, main sheet 336 KB 248 KB

No class lost its rule on 36 flamingo pages and 20 openmsp pages (two widths, chat open and closed) or 62 product-hub screens signed in.

Also: next-styles, the stylesheet inside each page's HTML

@flamingo-stack/openframe-frontend-core/next-styles (scripts/next-styles.cjs):

  • withInlineStyles(nextConfig) turns on Next's experimental.inlineCss (a config object or a config function). Every route's stylesheet is written into its HTML, the static export included, so a page paints without a second request.
  • measureStylesheet({ root, input, config, env }) builds the app's stylesheet the way its build does (Tailwind, minified) and reports raw and brotli bytes. The budget command (node .../dist/build/next-styles.cjs budget --input … --config … --budget …) fails past a stated size: every page now carries the sheet, so it has a ceiling.
  • Why inlining and not a smaller sheet alone: measured on flamingo.run, the stylesheet's own round trip (about 560 ms on slow 4G) held first paint, not its bytes. A sheet cut per route from the import graph was also measured and saved only 10%, because a site's shared layout reaches most of the design system.
  • Tests: src/__tests__/next-styles.test.ts.

Change-Set: refactor-per-page-css
ClickUp task: CU-17tkuw617h7 Refactor all CSS so every page ships only the styles it uses, by default

🤖 Generated with Claude Code

Change set flamingo-stack/openframe-oss-lib#2855: these pull requests are one change, reviewed together.

Linked work

  • …and 1 linked item not shown here

Linked by the Depends-On / Change-Set lines in these descriptions; this block is maintained by the hub.

…app's import graph

appStyleSources (./style-sources) lists the files an App Router app's served
routes import, its own and this library's per-module ESM build, tree-shaken, for
Tailwind's content: never the whole dist again. firstPaint leaves the lazily
loaded chat panel out, and EmbeddableChat's new loadStyles prop loads the host's
full stylesheet when the chat starts loading. esbuild moves to dependencies:
consumers run the scan.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@michaelassraf

Copy link
Copy Markdown
Member Author

@github-actions

github-actions Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

🦩 Flamingo Code Review

✅ No findings on the current head.

Advisory: findings do not block the merge.

Files Lines 🔴 Action required 🟠 Recommended 🔵 Informational
13 +737 / -9 0 0 0

✅ What this change does well

  • openframe-frontend-core/scripts/build-export-map.mjs fails the build fast if LAZY_STYLED names a file the build did not actually produce, preventing a silent drift between the deferred-styles list and the shipped artifacts.
  • openframe-frontend-core/src/tests/style-sources.test.ts and next-styles.test.ts exercise the new modules end-to-end against real temp filesystems and a real esbuild/tailwind build rather than mocking them, giving real confidence in the tree-shaking and budget behavior.
  • openframe-authorization-service-core/src/main/resources/templates/login.html replaces a render-blocking Google Fonts stylesheet request with inlined @‍font-face rules plus font-display: swap, directly removing a first-paint round trip.
  • embeddable-chat.tsx documents the new loadStyles prop clearly, including when it is called and what it is for (lines 195-200).
  • index.ts gates loadStyles behind the same load flag used for the lazy module load, so the host stylesheet is fetched exactly once, at the same moment the chat module starts loading, matching the test added in embeddable-chat-loading.test.tsx.
1 possible problem checked and ruled out, 1 after reading more of the repository
  • openframe-frontend-core/scripts/next-styles.d.ts:8 4 new or changed definitions have no test referencing them: The .d.ts file is type-only declarations (ambient types for the .cjs implementation) and is directly tested via next-styles.test.ts which imports and exercises withInlineStyles, measureStylesheet, and resolveImports; MeasureStylesheetOptions is exercised through measureStylesheet calls in the test, so the missing-test claim for this specific definition does not hold.

Review again. New commits are not reviewed until you ask:

  • Review the new commits: only what was pushed since this review
  • Review the whole diff again: everything, including what was already reviewed

Or comment @flamingo-review (new commits) or @flamingo-review full (everything). Add the flamingo-review-always label to review every push.

Started 2026-10-29 13:18 UTC · updated 2026-10-29 13:19 UTC · workflow run

michaelassraf and others added 2 commits October 28, 2026 16:13
…page's HTML and its size gate

withInlineStyles turns on Next's inlineCss for any app that uses the library;
measureStylesheet and the budget command build the app's stylesheet as its build
does and hold its brotli size to a budget.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… arguments

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@michaelassraf michaelassraf changed the title feat(styles): Tailwind content from an app's import graph CU-17tkuw617h7 feat(styles): Tailwind content from an app's import graph, and the stylesheet inside each page CU-17tkuw617h7 Oct 28, 2026
Comment thread openframe-frontend-core/package.json Resolved
michaelassraf and others added 2 commits October 28, 2026 17:20
…onfig

measureStylesheet wrote the resolved copy into a temporary folder, so a relative
@config (the hub's app/full.css) no longer resolved and Tailwind failed. The copy
now sits beside the input and is removed afterwards.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… state the import condition

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@michaelassraf michaelassraf added the flamingo-review Ask for one more review pass; removed automatically when the run is requested label Oct 29, 2026
@github-actions github-actions Bot removed the flamingo-review Ask for one more review pass; removed automatically when the run is requested label Oct 29, 2026
@michaelassraf

Copy link
Copy Markdown
Member Author

@flamingo-review full

Comment thread openframe-frontend-core/package.json Resolved
…build when LAZY_STYLED drifts

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@michaelassraf michaelassraf added the flamingo-review Ask for one more review pass; removed automatically when the run is requested label Oct 29, 2026
@github-actions github-actions Bot removed the flamingo-review Ask for one more review pass; removed automatically when the run is requested label Oct 29, 2026
michaelassraf and others added 2 commits October 29, 2026 09:14
…ist; next-styles is a command

The walk loads every non-code import as an empty module instead of naming each asset extension.
`next-styles budget` is a package bin that finds the app's stylesheet and Tailwind config itself.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… a stylesheet

Google's fonts stylesheet was the page's one blocking request; its @font-face rules now sit in the
page's own inline CSS, with the body font preloaded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@michaelassraf michaelassraf added the flamingo-review Ask for one more review pass; removed automatically when the run is requested label Oct 29, 2026
@github-actions github-actions Bot removed the flamingo-review Ask for one more review pass; removed automatically when the run is requested label Oct 29, 2026
michaelassraf and others added 2 commits October 29, 2026 09:53
…m's own fonts

The auth server packages openframe-frontend-core's fonts.css and woff2 files (one source, no copy)
and the page links them, in place of Google Fonts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@michaelassraf
michaelassraf merged commit fdef6c3 into main Oct 29, 2026
10 of 11 checks passed
@michaelassraf
michaelassraf deleted the refactor/per-page-css branch October 29, 2026 14:12
oleksandr-blip added a commit that referenced this pull request Oct 29, 2026
…0.0.815) into feature/directory-connection-customers. CU-17tkuw5z06b
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