Skip to content

Commit

Permalink
Fix CSS order when merging type change bundles (#8766)
Browse files Browse the repository at this point in the history
  • Loading branch information
devongovett authored Jan 17, 2023
1 parent 2172672 commit ddae31a
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 5 deletions.
6 changes: 3 additions & 3 deletions packages/bundlers/default/src/DefaultBundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -1155,10 +1155,10 @@ function createIdealGraph(
invariant(a !== 'root' && b !== 'root');
let bundleRootB = nullthrows(b.mainEntryAsset);
let mainBundleRoot = nullthrows(a.mainEntryAsset);
for (let asset of a.assets) {
b.assets.add(asset);
for (let asset of b.assets) {
a.assets.add(asset);
a.size += asset.stats.size;
}
a.assets = b.assets;
for (let depId of dependencyBundleGraph.getNodeIdsConnectedTo(
dependencyBundleGraph.getNodeIdByContentKey(String(otherNodeId)),
ALL_EDGE_TYPES,
Expand Down
1 change: 1 addition & 0 deletions packages/core/integration-tests/test/css-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ describe('css modules', () => {
assert(css.includes('height: 100px;'));
assert(css.includes('height: 300px;'));
assert(css.indexOf('_test') < css.indexOf('_intermediate'));
assert(css.indexOf('_intermediate') < css.indexOf('_composes5'));
});

it('should support composes imports for multiple selectors', async () => {
Expand Down
8 changes: 6 additions & 2 deletions packages/core/integration-tests/test/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,21 @@ describe('css', () => {
assertBundles(b, [
{
name: 'index.js',
assets: ['index.js', 'local.js'],
assets: ['index.js', 'local.js', 'c.js'],
},
{
name: 'index.css',
assets: ['index.css', 'local.css'],
assets: ['index.css', 'local.css', 'c.css'],
},
]);

let output = await run(b);
assert.equal(typeof output, 'function');
assert.equal(output(), 3);

let css = await outputFS.readFile(path.join(distDir, 'index.css'), 'utf8');
assert.ok(css.indexOf('.c {') < css.indexOf('.local {'));
assert.ok(css.indexOf('.local {') < css.indexOf('.index {'));
});

it('should bundle css dependencies in the correct, postorder traversal order', async () => {
Expand Down
3 changes: 3 additions & 0 deletions packages/core/integration-tests/test/integration/css/c.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.c {
color: red;
}
1 change: 1 addition & 0 deletions packages/core/integration-tests/test/integration/css/c.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('./c.css');
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require('./c.js');
require('./local.css');

exports.a = 1;
Expand Down
4 changes: 4 additions & 0 deletions packages/transformers/css/src/CSSTransformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ export default (new Transformer({
ref.specifier,
)};\n`;
dependencies.set(ref.specifier, d);
asset.addDependency({
specifier: ref.specifier,
specifierType: 'esm',
});
}
s += '${' + `${d}[${JSON.stringify(ref.name)}]` + '}';
}
Expand Down

0 comments on commit ddae31a

Please sign in to comment.