madyankin / madyankin/postcss-modules

@value or composes using other modules bypasses other postcss plugins

Open
#149 4 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
1.6k
Forks
88
PR merge metrics
No merged PRs in 30d

Description

I'm using Vite 4.0.4 (in a react project) which uses this postcss plugin for CSS Modules support.

I am also using the postcss-nesting plugin in my project. It appears that when classes are imported using the @value or composes syntax, the imported CSS bypasses other postcss plugins. In my case, this means nested CSS is leaking into my output.

For example when I use composes on a class in another modules file (which has nested CSS):

composes: formfield from '../../forms.module.css';

All of the nested code gets printed to the DOM - it somehow was not parsed into output CSS.

In textarea.module.css:

.textarea {
  composes: formfield from '../../forms.module.css';
}

in forms.module.css:

.formfield {
  cursor: text;

  &:not([disabled], [readonly]):focus {
    border-color: red;
  }
}
Expected CSS
.textarea {}

.formfield {
  cursor: text;
}

.formfield:not([disabled], [readonly]):focus {
  border-color: red;
}
Actual CSS
._formfield_1kfbh_12 {
  cursor: text;

  &:not([disabled], [readonly]):focus {
    border-color: red;
  }
}

._textarea_tj61n_1 {
}

Chromes then shows tons of invalid CSS properties in the inspector, and it breaks the actual CSS I'm trying to apply.

I originally filed the issue for postcss-nesting but they confirmed it's not their issue:

https://github.com/csstools/postcss-plugins/issues/796

Contributor guide

No contributing guide indexed for this repository

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 with the textarea.module.css and forms.module.css examples, using Vite 4.0.4 with postcss-nesting and CSS Modules. Trace how imported CSS from @value or composes moves through the plugin pipeline; done means nested selectors are transformed before the CSS reaches the DOM, matching the expected output.

Written by the indexing model from the issue text.

Assessment

Tech stack
css, javascript, react, vite
Domain
frontend, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.