Skip to content

[Bug]: @storybook/builder-vite duplicates postcss plugins during config resolution #33874

@anders-cognite

Description

@anders-cognite

Describe the bug

In Storybook using @storybook/react-vite, the Vite config resolution process during build duplicates the viteConfig.css.postcss.plugins array. As a result, PostCSS plugins are applied twice to the same CSS, causing transformations to be double-applied, and leading to, for example, postcss-prefixwrap now producing .scope .scope .selector, which is obviously a breaking bug.

This started after Storybook introduced the storybook:enforce-output-dir Vite plugin (PR #33740), which adds config hooks (config / configEnvironment) and triggers an additional config merge where the PostCSS plugins array becomes duplicated

Image Image

Reproduction link

https://69971850cc8d9694b2603cf1-mhkdpdawpi.chromatic.com

Reproduction steps

  1. Clone https://github.com/anders-cognite/storybook-vite-postcss-plugins-duplicated-repro
  2. Run the build-storybook command.
  3. Inspect the generated CSS output.

Expected Behavior:
CSS selectors should be prefixed with a single .hello-world, due to the PostCSS PrefixWrap('.hello-world') plugin defined in vite.config.ts.

Actual Behavior:
The PostCSS plugin processes the CSS twice due to array duplication, leading to a double .hello-world .hello-world prefix.

Reproduction link is to the chromatic build.

System

System:
│  OS: Linux 6.6 Ubuntu 24.04.3 LTS 24.04.3 LTS (Noble Numbat)
│  CPU: (16) x64 Intel(R) Core(TM) Ultra 7 265H
│  Shell: 5.9 - /usr/bin/zsh
│  Binaries:
│  Node: 24.11.1 - /run/user/1000/fnm_multishells/217352_1771508128317/bin/node
│  npm: 11.6.2 - /run/user/1000/fnm_multishells/217352_1771508128317/bin/npm
│  pnpm: 10.24.0 - /run/user/1000/fnm_multishells/217352_1771508128317/bin/pnpm
│  <----- active
│  npmPackages:
│  @storybook/react-vite: ^10.2.10 => 10.2.10
│  chromatic: ^15.1.1 => 15.1.1
│  eslint-plugin-storybook: ^10.2.10 => 10.2.10
│  storybook: ^10.2.10 => 10.2.10

Additional context

No response

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions