egoist / egoist/rollup-plugin-postcss

Extracted and inlined styles produce different source order

Open
#108 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
689
Forks
210
PR merge metrics
No merged PRs in 30d

Description

Converting a project from webpack I discovered that my css-classes were applied in a different order than previously when using rollup-plugin-postcss. I think the issue boils down to the module resolution working in a breadth-first order when it should really be depth-first. I've thrown together a simple test case which illustrates the issue here: https://github.com/dnjstrom/extract-css-source-order.

## In detail

Basically, if we have a file structure like this:
```js
// A.js
import B from B.js
import css from A.scss

// ...etc

// B.js
import css from B.scss

// ...etc
```

Then we get a dependency-tree like so:

```
A.js
/ \
B.js A.scss
/
B.scss
```

The files will be transformed and extracted breadth-first (row-by-row):

```
A.js -> B.js -> A.scss -> B.scss
```

meaning A's classes will be defined above B's in the extracted file. This results in B's styles overriding A's instead of the other way around, if they're applied to the same element (a situation which is very common with React components).

The expected behavior is to do depth-first (column-by-column):

```
A.js -> B.js -> B.scss -> A.scss
```

Here A's styles override B's, as they are supposed to, and this is also what happens when the styles are inlined.

## Conclusions

The `extract` feature of rollup-plugin-postcss is unlikely to work whenever you have an overlap of styles, which is likely a lot of projects.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.