Repository navigation
build(style): compile isolated Tailwind v4 into swagger-ui.css - #11134
Conversation
There was a problem hiding this comment.
🟡 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.cssacross 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
765bd14 to
4853a75
Compare
4853a75 to
150629d
Compare
There was a problem hiding this comment.
🔵 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
|
sending virtual approval ✅ |
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>
c68e654 to
a0891d1
Compare
|
🎉 This PR is included in version 5.36.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |

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.cssis a second entry of theswagger-uichunk inwebpack/stylesheets.js,dev.jsanddev-e2e.js. It imports Tailwind's theme and utilities only (no preflight) with:suiprefix (sui:flex, variables--sui-*);important;source(".."), so classes are scanned acrosssrc/;dark:variant on.dark-mode.Own webpack rule. The Tailwind CSS gets a
.cssrule limited tosrc/style, withoutpostcss-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@propertyregistrations become--sui-tw-*, and the globalpropertieslayer (and any other layer) moves underswagger-ui.*. Without it, Tailwind's raw output contains an unprefixed global@layer propertiesand@property --tw-*rules that would clash with a host page's own Tailwind.Dead config removed. The
optimization.splitChunksstylesgroup instylesheets.jsnever matched.scssmodules, and it split the Tailwind CSS into a separatestyles.css. The SCSS part ofswagger-ui.cssis byte-identical before and after.Enforcement. A new artifact test,
test/build-artifacts/tailwind-isolation.ts, parses the built CSS and fails on:swagger-ui.*;--tw-;@propertynot named--sui-*;.sui\:selector in the utilities layer (which would mean preflight is back);--sui-*.jest.artifact.config.jsnow also matches.ts. The test follows that directory's own.eslintrc(single quotes, semicolons, no@prettierpragma). The add-oas-support conventions script's PRAGMA check therefore skipstest/build-artifacts/.Linting.
lint-stylesand lint-staged now coversrc/**/*.css.Docs.
CLAUDE.mdgets the Tailwind rules (static class names only,sui:prefix, don't touch the isolation setup without the spec) and a corrected lint-staged snippet. Theui-shellspec gets a "Styling with Tailwind" section, andarchitecturegets 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.cssgets 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'stwprefix or theme variables. The artifact test keeps it that way.Points to review closely:
webpack/stylesheets.js;test:artifactnow needs a freshnpm run build. The committeddist/swagger-ui.csspredates 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, includingtailwind-isolation.tailwind-isolationwith the namespacing step temporarily removed: 2 of 5 checks fail, as intended.swagger-ui.csscompared 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-stylesreports only the 2 errors that already exist onmain(_models.scss:198,main.scss:7).npm run test:unit: 909 passed, 12 skipped.npm run e2e:typecheckclean;npm run e2e: 653 passed, 4 skipped. This ran on a tree whose code and config are identical to this PR.Dependencies:
tailwindcssand@tailwindcss/postcssare pinned at=4.3.4.postcssmoves from 8.5.23 to the 8.5.25+ that@tailwindcss/postcssrequires.@tailwindcss/oxidehas no install scripts, soallowScriptsis unchanged.Screenshots (if appropriate):
N/A: no visual change.
Checklist
My PR contains...
src/is unmodified: changes to documentation, CI, metadata, etc.)package.json)My changes...
Documentation
Automated tests