Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

Fix CSS layer order in dev mode (#491)

Andrey Goderd8f7350eb82d
diff --git a/apps/storybook/.storybook/main.ts b/apps/storybook/.storybook/main.ts
index a6494fc411..29c4a0236a 100644
--- a/apps/storybook/.storybook/main.ts
+++ b/apps/storybook/.storybook/main.ts
@@ -59,6 +59,25 @@ const config: StorybookConfig = {
return {
...config,
plugins: [
+ // Declare CSS layer order before StyleX injects its virtual CSS.
+ // In Vite dev mode the StyleX unplugin's transformIndexHtml injects
+ // a <link> for /virtual:stylex.css before preview.tsx CSS imports
+ // are processed, which would otherwise cause priority1-9 layers to
+ // be declared first (lowest priority) and reset/typography last
+ // (highest priority) — the reverse of what we need.
+ {
+ name: 'xds-css-layer-order',
+ transformIndexHtml() {
+ return [
+ {
+ tag: 'style',
+ children:
+ '@layer reset, typography, priority1, priority2, priority3, priority4, priority5, priority6, priority7, priority8, priority9;',
+ injectTo: 'head-prepend',
+ },
+ ];
+ },
+ },
...filteredPlugins,
stylex.vite({
// Use production mode with CSS extraction