postcss-import: Incorrect nested import ordering
I just discovered this bug, where two imports that both import the same file can end up with the imported file out-of-order intermittently (due to parallel loading).
For example, if two separate files import base.css, in some cases the second file will process first and actually include it. Whereas the first file will not (due to de-duping) and then the result will be out-of-order and can affect the resulting applied styles (or variable definitions).
I have a full test case in my branch: https://github.com/adam-h/postcss-import/commit/569ea1ed4da1e7b84f1d190937a8341bbfac5b3b
Note how the first import is delayed so that the second will always process first (removing the randomness of occurance due to the filesystem).
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 16 (6 by maintainers)
Commits related to this issue
- [wip] fix inconsistent import order, closes #168 — committed to goto-bus-stop/postcss-import by goto-bus-stop 8 years ago
- [wip] fix inconsistent import order, closes #168 — committed to goto-bus-stop/postcss-import by goto-bus-stop 8 years ago
- Force the version of postcss-import due to bugs https://github.com/postcss/postcss-import/issues/168 — committed to googleanalytics/ga-dev-tools by philipwalton 8 years ago
- Fixed: Nested import ordering (#236) Had to edit a test that depended on the old, incorrect behavior Closes #168 — committed to postcss/postcss-import by RyanZim 8 years ago
- Brought in recent changes from postcss-import to fix ordering issues. Closing issue: https://github.com/postcss/postcss-import/issues/168 — committed to sebastian-software/postcss-smart-import by swernerx 8 years ago
- Force the version of postcss-import due to bugs https://github.com/postcss/postcss-import/issues/168 — committed to TopDevSun0/ga-dev-tools by deleted user 8 years ago
Please use v7 while it’s resolved.
As I said before, I am not the author of this code base, and the author decided to ignore this project for some reasons (that’s why I talked about reverting to v7, which is a codebase I know). Anyway I will try to give you some pointers.
At the end, resolveImportId() mutate the initial passed statement (called stmt) childrens. The naming of “result” inside the function is a bit confusing since the parent block level also have a “result” variable.
I merged a failing test into master, so know you can do the following:
ava test/order.jsto trigger the failure and iterate with this.@RyanZim maybe everything is a mess because of this line https://github.com/postcss/postcss-import/blob/6bbcdbd9a6b52ad45bd1ab4853b98b68719c9ca5/index.js#L166
Promise.all might resolve without taking the correct expected order (really not sure about that, but that may be a clue)
Done 😃 https://github.com/postcss/postcss-import/pull/169