ReviewOS

stacks/stx

Dev-server crosswind pass omits grid utilities on a large/component-heavy page (works in isolation)

#1749
Closed glennmichael123 opened this 22 days ago · 1 comment
22 days ago

Summary

In an stx app served by bun-plugin-stx with @cwcss/crosswind, the dev server's on-the-fly crosswind pass omits grid utilities for the dashboard page: elements with grid grid-cols-* compute to display:block, and .grid / .grid-cols-* are absent from the served <style data-crosswind="generated"> — while .gap-4 on the same elements is present. So crosswind is being invoked, but not given (or not emitting) the grid classes for this page.

Crosswind core is fine — the same classes work in isolation (below) — so this is the stx ↔ crosswind serve integration (how bun-plugin-stx feeds content to crosswind), not crosswind.

Environment

  • @stacksjs/stx 0.2.70, bun-plugin-stx 0.2.70
  • @cwcss/crosswind 0.2.4, Bun 1.3.13, macOS

Evidence (dashboard page)

A grid container: class="grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-6 gap-4 p-6"

  • computed display: block, grid-template-columns: none
  • served stylesheet: .grid{display:grid} → missing; .grid-cols-6 → missing; .gap-4 → present

Result: the cards stack vertically instead of laying out in a 6-column grid.

What works (rules out crosswind core and @include)

  • A minimal view <div class="grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-6 gap-4"> → renders 6 columns at lg.
  • The same via an @include'd partial → also renders grid (display:grid).
  • crosswind build scanning the project's .stx files → output includes grid-cols-6.

Reproduction

I could not minimize it — every minimal case renders grid correctly; only the full dashboard render drops it. It reproduces in the ts-analytics dashboard: bun dev (+ the API server), load /dashboard?siteId=<id> → the stat cards stack vertically instead of a grid.

The contrast (minimal works, full page doesn't) suggests something scale- or content-specific in how the serve pass collects classes for crosswind on a large, component-heavy page (the grid classes live in an @include'd StatsRow and in the view's own panel rows; neither generates on the dashboard, while both generate in isolation).

22 days ago

Fixed in 29b6093580 (on main). Your diagnosis was spot-on — it's the stx↔crosswind serve integration, specifically the shell composition.

Root cause: processShell runs the app shell through processDirectives at top level, so the shell already carries its own <style data-crosswind="generated"> covering the shell's classes (the nav/layout used gap-4). After composeShellWithPage embeds the page, the page-level injectCrosswindCSS saw that existing data-crosswind="generated" marker and early-returned — so the page's own classes were never scanned. That's exactly why .gap-4 (shell) was present but .grid / .grid-cols-* (page-only) were missing, and why it only reproduced on a real shell-wrapped page (minimal pages have no shell → no pre-injected marker → they injected fine, which is why you couldn't minimize it).

I reproduced it end-to-end: processShell → composeShellWithPage → injectCrosswindCSS → .grid absent, .gap-4 present. Both the @include'd StatsRow grid and the view's panel-row grids drop together because all page-level classes are skipped, not those two specifically.

Fix: injectCrosswindCSS no longer early-returns on a pre-existing generated style. It regenerates from the full composed content and replaces the existing style (dropping duplicates), so the single emitted stylesheet is the union of shell + page classes — with exactly one Preflight reset. The layout-wrapped path is unaffected (it injects once, on content with no pre-existing marker), and SPA fragments use a different marker (data-crosswind="fragment") so they're untouched.

Pinned by test/dev-server/crosswind-shell.test.ts. Full suite 9266 pass / 0 fail. A bun dev reload of the ts-analytics dashboard should now show the 6-column grid.

Sign in to comment on this issue.