Skip to content

Inconsistent cssTarget value, leading to duplicated CSS #20505

@brillout

Description

@brillout

Describe the bug

The value of cssTarget should be consistent between client and server.

But that isn't the case, for example with following config:

// vite.config.js

export default {
  environments: {
    ssr: {
      build: {
        target: 'es2022'
      }
    }
  }
}

The value of config.build.cssTarget differs between:

  • Client-side: es2022
  • Server-side: [ 'chrome107', 'edge107', 'firefox104', 'safari16' ]

I believe changing ssr.build.target shouldn't also change cssTarget.

One issue is that it leads to CSS duplication when frameworks try to dedupe the CSS generated redundantly between client and server. Example with Vike: vikejs/vike#1815 (comment).

Another example of why this is an issue: @cloudfalre/vite-plugin sets ssr.build.target to es2022 which makes sense (the server code targets Cloudflare's workerd runtime), but it doesn't make sense that it also changes cssTarget.

Reproduction

https://github.com/brillout/repro_vite-css-duplication

Steps to reproduce

No response

System Info

System:
    OS: Linux 6.8 Ubuntu 24.04.2 LTS 24.04.2 LTS (Noble Numbat)
    CPU: (8) x64 Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz
    Memory: 3.29 GB / 7.52 GB
    Container: Yes
    Shell: 5.2.21 - /bin/bash
  Binaries:
    Node: 22.14.0 - ~/.nvm/versions/node/v22.14.0/bin/node
    Yarn: 1.22.22 - ~/.nix-profile/bin/yarn
    npm: 10.9.2 - ~/.nvm/versions/node/v22.14.0/bin/npm
    pnpm: 9.15.9 - ~/.local/share/pnpm/pnpm
    bun: 1.1.24 - ~/.bun/bin/bun
    Watchman: 2024.03.11.00 - /home/rom/.nix-profile/bin/watchman
  Browsers:
    Chrome: 138.0.7204.168
  npmPackages:
    @vitejs/plugin-react: ^4.6.0 => 4.7.0 
    vite: ^7.0.0 => 7.0.6

Used Package Manager

pnpm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions