#36392·nuxt

Dev server duplicates layer css links (@fs + non-@fs), duplicate lands after the app's own css

Author: SundwellCreated Sep 23, 2026Updated Sep 28, 2026
Labels4.x

Dev server emits duplicate stylesheet links for layer css (@fs + non-@fs), duplicate lands after the app's own css

Environment

npx nuxi info printed an empty table in my repro workspace (pnpm workspace root without its own nuxt install), so here's the info by hand

  • Nuxt: 4.5.2
  • Nitro: 2.13.4
  • Vite: 8.3.0
  • Vue: 3.5.43
  • Node: 24.21.0
  • Package manager: pnpm 12.5.1 (workspace)
  • Builder: vite
  • OS: Linux (WSL2)

Reproduction

Minimal pnpm workspace, no public repo since I built it offline, paste this and run it

bash
mkdir nuxt-css-dup-repro && cd nuxt-css-dup-repro

cat > pnpm-workspace.yaml <<'EOF'
packages:
  - app
  - layer
EOF

cat > package.json <<'EOF'
{ "name": "nuxt-css-dup-repro", "private": true }
EOF

mkdir -p layer/app/assets/css layer/app/components
cat > layer/package.json <<'EOF'
{
  "name": "@repro/layer",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "main": "./nuxt.config.ts",
  "devDependencies": { "nuxt": "4.5.2", "vue": "3.5.43" }
}
EOF
cat > layer/nuxt.config.ts <<'EOF'
import { defineNuxtConfig } from 'nuxt/config'

export default defineNuxtConfig({
  $meta: { name: 'storefront' },
  css: ['#layers/storefront/app/assets/css/tokens.css'],
})
EOF
cat > layer/app/assets/css/tokens.css <<'EOF'
:root { --c: red; }
EOF
cat > layer/app/components/LayerBadge.vue <<'EOF'
<template><span class="layer-badge">layer</span></template>
<style scoped>
.layer-badge { font-weight: bold; }
</style>
EOF

mkdir -p app/app/assets/css
cat > app/package.json <<'EOF'
{
  "name": "app",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "dependencies": { "@repro/layer": "workspace:*" },
  "devDependencies": { "nuxt": "4.5.2", "vue": "3.5.43" }
}
EOF
cat > app/nuxt.config.ts <<'EOF'
import { defineNuxtConfig } from 'nuxt/config'

export default defineNuxtConfig({
  extends: ['@repro/layer'],
  compatibilityDate: '2026-01-01',
  css: ['~/assets/css/theme.css'],
})
EOF
cat > app/app/assets/css/theme.css <<'EOF'
:root { --c: green; }
EOF
cat > app/app/app.vue <<'EOF'
<template>
  <div>
    <p style="color: var(--c)">hello</p>
    <LayerBadge />
  </div>
</template>
EOF

pnpm install
pnpm --filter app exec nuxt dev --port 3456

Then in another terminal

bash
curl -s http://localhost:3456/ | grep -oE '<link[^>]*rel="stylesheet"[^>]*>'

Same result with the layer css given as a full path instead of the #layers alias, so the alias isn't the trigger

typescript
import { join } from 'node:path'
css: [join(import.meta.dirname, 'app/assets/css/tokens.css')],

Describe the bug

A site app extends a local layer through a pnpm workspace dependency The layer registers global css with css: ['#layers/storefront/...tokens.css'] The app registers its own css that overrides the layer's custom properties on :root

In nuxt dev the SSR html head links the layer css twice, once as /_nuxt/@fs/<abs path> and once as /_nuxt/<abs path without @fs>, and the second copy lands after the app's own css

<link rel="stylesheet" href="/_nuxt/@fs/.../layer/app/assets/css/tokens.css">
<link rel="stylesheet" href="/_nuxt/assets/css/theme.css">
<link rel="stylesheet" href="/_nuxt/.../layer/app/assets/css/tokens.css">

Both urls serve the same css, but css cascade order means the layer's --c: red wins over the app's --c: green until the client JS runs and Vite re-injects styles in the right order With JS disabled the app never gets the app's own value On every reload there's a visible flash / jump from the wrong value to the right one

A layer component's <style scoped> is linked twice the same way (see LayerBadge.vue in the reproduction), same @fs + non-@fs pair

A production build is correct, one entry css, right order, this only shows up in nuxt dev

Additional context

Traced this to collectDevCss in @nuxt/vite-builder, src/utils/css.ts (compiled at dist/index.mjs around line 254 in 4.5.2)

javascript
function collectDevCss(nuxt, moduleGraph) {
  const urls = new Set();
  const files = new Set();
  for (const [url, node] of moduleGraph.urlToModuleMap.entries()) {
    if (!isCSS(url) || "raw" in getQuery(url)) continue;
    const importers = node.importers;
    if (importers.size && [...importers].every((i) => i.id && "raw" in getQuery(i.id))) continue;
    urls.add(url);
    if (node.file) files.add(node.file);
  }
  for (const entry of resolveGlobalCss(nuxt)) if (!files.has(entry.file)) urls.add(entry.url);
  return [...urls];
}

For a css file outside the app root, Vite's dev module graph holds two url keys for the same module, /@fs/<abs> and /<abs> (without @fs) The loop over moduleGraph.urlToModuleMap adds every url it sees with no dedup by node.file, so both urls for the same layer css module get added to the urls set The dedup by node.file only happens in the second loop, for the resolveGlobalCss entries, which is a different code path (used to seed the manifest before the ssr module graph has loaded the importing component)

Deduping the graph loop by node.file the same way the second loop already does should fix both the global css and the component scoped style duplicates

This looks distinct from #35831 / #35834 (dedupe and normalise global css links in dev, released in 4.5.1), that fix covers resolveGlobalCss entries not already in the graph, not the case here where the graph itself yields two urls for one file

Logs

$ curl -s http://localhost:3456/ | grep -oE '<link[^>]*>'
<link rel="stylesheet" href="/_nuxt/@fs/.../layer/app/assets/css/tokens.css" crossorigin>
<link rel="stylesheet" href="/_nuxt/assets/css/theme.css" crossorigin>
<link rel="stylesheet" href="/_nuxt/.../layer/app/assets/css/tokens.css" crossorigin>
<link rel="stylesheet" href="/_nuxt/@fs/.../layer/app/components/LayerBadge.vue?vue&type=style&index=0&scoped=c6f20af9&lang.css" crossorigin>
<link rel="stylesheet" href="/_nuxt/.../layer/app/components/LayerBadge.vue?vue&type=style&index=0&scoped=c6f20af9&lang.css" crossorigin>