sveltejs / sveltejs/kit

CSS output does not respect Vite build target

Open
#13,732 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

vite
Dominant language
JavaScript
Stars
20.8k
Forks
2.3k
Avg merge
1d 16h
Merged PRs (30d)
156

Description

Describe the bug

Browser native CSS nesting should be flattened based on the Vite default build.target, but is not.

Reproduction

Vanilla Vite project correctly builds the following CSS:

import './style.css';

document.querySelector<HTMLDivElement>('#app')!.innerHTML = `<span>Hello,&nbsp;</span>`;
/* Nesting requires Chrome 120, Safari 17.2 */
/* Reference https://caniuse.com/css-nesting */
span {
  color: red;
  &::after {
    content: 'World!';
  }
}
/* Default option (targeting Safari 14)  */
span{color:red}span:after{content:"World!"}

/* With build: { cssTarget: 'safari17.2' } */
span{color:red;&:after{content:"World!"}}

This is not the case with a SvelteKit template:

┌  Welcome to the Svelte CLI! (v0.8.1)
│
◇  Which template would you like?
│  SvelteKit minimal
│
◇  Add type checking with TypeScript?
│  Yes, using TypeScript syntax
│
◆  Project created
│
◇  What would you like to add to your project? (use arrow keys / space bar)
│  none
<!-- src\routes\+page.svelte -->
<span>Hello,&nbsp;</span>

<style>
  span {
    color: red;
    &::after {
      content: 'World!';
    }
  }
</style>
/* .svelte-kit\output\client\_app\immutable\assets\_page.CmDdIB0i.css */
/* With build: { cssTarget: 'safari14' } */
span.svelte-yc2s4t{color:red}span.svelte-yc2s4t:after{content:"World!"}

/* .svelte-kit\output\client\_app\immutable\assets\_page.D4Ercq9S.css */
/* Default option (targeting Safari 14)  */
span.svelte-yc2s4t{color:red;&:after{content:"World!"}}
Logs

System Info
System:
  OS: Windows 11 10.0.26100
  CPU: (8) x64 Intel(R) Core(TM) Ultra 7 258V
  Memory: 9.22 GB / 31.51 GB
Binaries:
  Node: 22.14.0 - ~\AppData\Local\fnm_multishells\12668_1745374883481\node.EXE
  npm: 10.9.2 - ~\AppData\Local\fnm_multishells\12668_1745374883481\npm.CMD
  pnpm: 10.9.0 - ~\AppData\Local\fnm_multishells\12668_1745374883481\pnpm.CMD
Browsers:
  Edge: Chromium (131.0.2903.112)
npmPackages:
  @sveltejs/adapter-auto: ^4.0.0 => 4.0.0 
  @sveltejs/kit: ^2.16.0 => 2.20.7 
  @sveltejs/vite-plugin-svelte: ^5.0.0 => 5.0.3 
  svelte: ^5.0.0 => 5.28.2 
  vite: ^6.2.5 => 6.3.2
Severity

serious, but I can work around it

Additional Information

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue from src/routes/+page.svelte in a SvelteKit minimal project, comparing the default build target with an explicit cssTarget. Trace how the generated CSS output is produced and verify that the default target flattens the nested selector while the newer target preserves it.

Written by the indexing model from the issue text.

Assessment

Tech stack
css, javascript, typescript, vite
Domain
build-system, frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.