vercel / vercel/next.js

Chained CSS Module `composes` not working with Turbopack

Open
#85,296 4 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

CSS Turbopack
Dominant language
JavaScript
Stars
142k
Forks
32.4k
Avg merge
2d 14h
Merged PRs (30d)
351

Description

Link to the code that reproduces this issue

https://codesandbox.io/p/devbox/next-turbo-css-modules-chained-composes-issue-hjyd9c

To Reproduce
  1. Start the app in Turbopack mode (npm run dev).
  2. Note that the "text" is styled bold and italic, but not underlined.
  3. Restart the app in Webpack mode (npm run devWebpack).
  4. Note that the "text" is now also underlined.
Current vs. Expected behavior

Consider the following SCSS code which is used in the linked reproduction:

.a {
    text-decoration: underline;
}

.b {
    composes: a;
    font-style: italic;
}

.c {
    composes: b;
    font-weight: bold;
}

The sample text has className={styles.c}.

Using Webpack, this composes to "c b a", which is the expected behaviour. I.e. It supports chaining of composes.

Using Turbopack, it composes only to "c b", which is unexpected.

Turbopack not supporting chaining of composes means it fails to build our web apps correctly, as they have been coded to depend on this behaviour.

Provide environment information
Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP PREEMPT_DYNAMIC Sun Aug  6 20:05:33 UTC 2023
  Available memory (MB): 4102
  Available CPU cores: 2
Binaries:
  Node: 20.9.0
  npm: 9.8.1
  Yarn: 1.22.19
  pnpm: 8.10.2
Relevant Packages:
  next: 16.0.1-canary.1 // Latest available version is detected (16.0.1-canary.1).
  eslint-config-next: N/A
  react: 19.2.0
  react-dom: 19.2.0
  typescript: 5.9.3
Next.js Config:
  output: N/A
Which area(s) are affected? (Select all that apply)

CSS, Turbopack

Which stage(s) are affected? (Select all that apply)

next dev (local), next build (local)

Additional context

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

Start with the linked CodeSandbox reproduction and run npm run dev and npm run devWebpack to compare the generated class composition. Trace Turbopack's CSS Modules handling for chained composes; done means Turbopack produces c b a and preserves the underline in both next dev and next build.

Written by the indexing model from the issue text.

Assessment

Tech stack
nextjs, react, scss
Domain
build-system, frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.