Skip to content

build(style): compile isolated Tailwind v4 into swagger-ui.css - #11134

Merged
glowcloud merged 6 commits into
docs/spec-graphfrom
build/tailwind-v4
Nov 23, 2026
Merged

glowcloud merged 6 commits into
docs/spec-graphfrom
build/tailwind-v4

Conversation

@robert-hebel-sb

@robert-hebel-sb robert-hebel-sb commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Stack 1/3, based on #11133 (draft spec graph). Next: #11135 (opt-in unified JSON Schema view for 3.1/3.2), then #11136 (2.0/3.0 dialects).

Description

This PR compiles Tailwind CSS v4 into the existing single swagger-ui.css, isolated so it can't affect host pages. No component uses it yet, so nothing changes visually. About 120 bytes are added: the Tailwind license header and the layer-order line.

  • Entry. src/style/tailwind.css is a second entry of the swagger-ui chunk in webpack/stylesheets.js, dev.js and dev-e2e.js. It imports Tailwind's theme and utilities only (no preflight) with:

    • the sui prefix (sui:flex, variables --sui-*);
    • important;
    • source(".."), so classes are scanned across src/;
    • a dark: variant on .dark-mode.
  • Own webpack rule. The Tailwind CSS gets a .css rule limited to src/style, without postcss-preset-env, whose cascade-layers polyfill would flatten the layers.

  • Namespacing step. A small inline PostCSS plugin renames what Tailwind hard-codes: --tw-* variables and their @property registrations become --sui-tw-*, and the global properties layer (and any other layer) moves under swagger-ui.*. Without it, Tailwind's raw output contains an unprefixed global @layer properties and @property --tw-* rules that would clash with a host page's own Tailwind.

  • Dead config removed. The optimization.splitChunks styles group in stylesheets.js never matched .scss modules, and it split the Tailwind CSS into a separate styles.css. The SCSS part of swagger-ui.css is byte-identical before and after.

  • Enforcement. A new artifact test, test/build-artifacts/tailwind-isolation.ts, parses the built CSS and fails on:

    • any layer outside swagger-ui.*;
    • any leaked --tw-;
    • any @property not named --sui-*;
    • any non-.sui\: selector in the utilities layer (which would mean preflight is back);
    • any theme variable not named --sui-*.

    jest.artifact.config.js now also matches .ts. The test follows that directory's own .eslintrc (single quotes, semicolons, no @prettier pragma). The add-oas-support conventions script's PRAGMA check therefore skips test/build-artifacts/.

  • Linting. lint-styles and lint-staged now cover src/**/*.css.

  • Docs. CLAUDE.md gets the Tailwind rules (static class names only, sui: prefix, don't touch the isolation setup without the spec) and a corrected lint-staged snippet. The ui-shell spec gets a "Styling with Tailwind" section, and architecture gets the build table row and the artifact gate.

Motivation and Context

Tailwind is the styling foundation for new UI code, starting with the opt-in unified JSON Schema view in #11135. swagger-ui.css gets loaded into arbitrary host pages, often next to the host's own Tailwind. So the output must never reset host elements, never join or reorder the host's cascade layers, and never collide with a host's tw prefix or theme variables. The artifact test keeps it that way.

Points to review closely:

  • the namespacing plugin in webpack/stylesheets.js;
  • test:artifact now needs a fresh npm run build. The committed dist/swagger-ui.css predates Tailwind; CI already builds first.

How Has This Been Tested?

  • npm run build: compiled successfully.
  • npm run test:artifact: 4 suites and 8 tests pass, including tailwind-isolation.
  • tailwind-isolation with the namespacing step temporarily removed: 2 of 5 checks fail, as intended.
  • SCSS part of swagger-ui.css compared with the build before this change: byte-identical.
  • npm run lint-errors, npx tsc --noEmit -p tsconfig.json, npx stylelint src/style/tailwind.css: clean. npm run lint-styles reports only the 2 errors that already exist on main (_models.scss:198, main.scss:7).
  • npm run test:unit: 909 passed, 12 skipped.
  • npm run e2e:typecheck clean; npm run e2e: 653 passed, 4 skipped. This ran on a tree whose code and config are identical to this PR.

Dependencies:

  • tailwindcss and @tailwindcss/postcss are pinned at =4.3.4.
  • The lockfile carries the oxide/lightningcss native binaries for every platform.
  • postcss moves from 8.5.23 to the 8.5.25+ that @tailwindcss/postcss requires.
  • @tailwindcss/oxide has no install scripts, so allowScripts is unchanged.

Screenshots (if appropriate):

N/A: no visual change.

Checklist

My PR contains...

  • No code changes (src/ is unmodified: changes to documentation, CI, metadata, etc.)
  • Dependency changes (any modification to dependencies in package.json)
  • Bug fixes (non-breaking change which fixes an issue)
  • Improvements (misc. changes to existing features)
  • Features (non-breaking change which adds functionality)

My changes...

  • are breaking changes to a public API (config options, System API, major UI change, etc).
  • are breaking changes to a private API (Redux, component props, utility functions, etc.).
  • are breaking changes to a developer API (npm script behavior changes, new dev system dependencies, etc).
  • are not breaking changes.

Documentation

  • My changes do not require a change to the project documentation.
  • My changes require a change to the project documentation.
  • If yes to above: I have updated the documentation accordingly.

Automated tests

  • My changes can not or do not need to be tested.
  • My changes can and should be tested by unit and/or integration tests.
  • If yes to above: I have added tests to cover my changes.
  • If yes to above: I have taken care to cover edge cases in my tests.
  • All new and existing tests passed.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The Tailwind isolation pass can corrupt CSS literals and asset URLs while leaving keyframes global, and its artifact checks lack representative coverage and miss unlayered resets.

5 open issues
What changed in this PR

Integrates Tailwind v4 into Swagger UI’s existing stylesheet pipeline as groundwork for the upcoming opt-in unified schema view. No current component styling changes.

Changes:

  • Combines prefixed Tailwind utilities and legacy SCSS in swagger-ui.css across production and development builds.
  • Adds namespace processing, artifact isolation checks, and CSS lint coverage.
  • Pins Tailwind dependencies and documents the styling contract.
File Description
webpack/​stylesheets.js Adds Tailwind processing and namespaces variables and layers.
webpack/​dev.js Includes Tailwind in the development stylesheet entry.
webpack/​dev-e2e.js Includes Tailwind in the end-to-end stylesheet entry.
test/​build-artifacts/​tailwind-isolation.ts Adds built-CSS isolation assertions.
src/​style/​tailwind.css Defines prefixed imports and the dark-mode variant without preflight.
src/​core/​components/​SPEC.md Documents styling isolation and browser requirements.
package.json Adds Tailwind dependencies and CSS lint commands.
package-lock.json Locks Tailwind and its supporting dependencies.
config/​jest/​jest.artifact.config.js Enables discovery of TypeScript artifact tests.
CLAUDE.md Adds Tailwind guidance and updates linting documentation.
architecture.md Documents the combined stylesheet and isolation gate.
.lintstagedrc Adds staged source CSS linting.
.claude/​skills/​add-oas-support/​scripts/​check-plugin-conventions.mjs Exempts artifact tests from the pragma check.

Review effort: Max

Comment thread webpack/stylesheets.js Resolved
Comment thread webpack/stylesheets.js Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The artifact guard misses single-colon global resets and incorrectly rejects valid scoped sui:file: utilities, making isolation checks unreliable.

3 open issues
3 resolved since last review

Review effort: Max

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The isolation gate can admit global styles because it accepts prefixed classes inside selector alternatives or negations that still match unscoped host elements.

2 open issues
2 resolved since last review

Review effort: Max

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The new Tailwind v4 native dependencies and custom PostCSS namespacing for swagger-ui.css require maintainer sign-off, while CSS isolation remains unverified because a real build could not be run.

1 open issue
1 resolved since last review

Review effort: Max

@glowcloud
glowcloud marked this pull request as ready for review November 17, 2026 12:38
@glowcloud
glowcloud requested a review from cka121 November 17, 2026 12:38
@robert-hebel-sb

Copy link
Copy Markdown
Contributor Author

sending virtual approval ✅

robert-hebel-sb and others added 5 commits November 23, 2026 07:48
The namespace pass rewrote every `--tw-` in a declaration value, so a
string or a url() holding that text was changed too, for example
url(/a/--tw-logo.svg) became url(/a/--sui-tw-logo.svg).

Rename only the identifiers: in var() and bare, as in the
transition-property list Tailwind emits for gradients. Strings and
url() stay as written.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
- Accept the :where() and :is() wrappers Tailwind puts around some
  utility selectors, for example space-x-* and divide-*.
- Fail on the global keyframes of Tailwind's default theme (spin, ping,
  pulse, bounce), which would collide with a host page.
- Fail on preflight signature rules, which the utilities-layer check
  did not cover.
- Ignore strings and url() in the --tw- leak check, as the namespace
  pass does.

The ui-shell spec lists the two new checks.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The check only accepted selectors that start with a sui: class, or one
wrapper around it. Tailwind also emits :is(:where(.sui:peer):hover ~ ...)
for peer-* and group-* variants, which that rejected.

Check the classes a selector references instead: at least one sui:
class, and no class that is not sui:-prefixed apart from the .dark-mode
class of the dark variant. Bare resets (*, button, :root) and selectors
referencing host classes still fail.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The production build minifies ::before and ::after to :before and
:after, so the reset rule *,:after,:before,::backdrop was only caught
through its ::file-selector-button siblings. Normalize them before
comparing.

A sui:file: utility styles ::file-selector-button of its own element
and was rejected as preflight. Apply that check only to selectors that
are not sui:-scoped.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The selector check accepted any selector that mentioned a sui: class,
so :is(.sui:flex, button) and :not(.sui:hidden) passed although they
match host elements. It also rejected valid arbitrary variants that
reference a host class.

A selector now has to require a sui: class to match: such a class
outside :not() and :has(), or a :is()/:where() whose every alternative
has one. The check uses postcss.list.comma and needs no dependency, and
fails closed on a shape it does not model. Regression cases cover the
alternatives, negations, escapes and strings.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@glowcloud
glowcloud merged commit 918b536 into main Nov 23, 2026
9 checks passed
@swagger-bot

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 5.36.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants