Skip to content

Extracted and inlined styles produce different source order #108

Open

Description

@dnjstrom

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:

// 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.

Activity

  1. dnjstrom commented on Jun 1, 2018

    @dnjstrom
    ContributorAuthor

    Probably related: #96

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions