Skip to content

Commit 57372e1

Browse files
authored
fix: css infinite reload when module chunk enabled (#11536)
* fix: align webpack remove js module check * test: add test for only css change while single runtime chunk & module chunk setting
1 parent abac48a commit 57372e1

File tree

8 files changed

+94
-5
lines changed

8 files changed

+94
-5
lines changed

crates/rspack_plugin_runtime/src/module_chunk_format.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,6 @@ async fn render_chunk(
122122
chunk_ukey: &ChunkUkey,
123123
render_source: &mut RenderSource,
124124
) -> Result<()> {
125-
// Skip processing if the chunk doesn't have any JavaScript
126-
if !chunk_has_js(chunk_ukey, compilation) {
127-
return Ok(());
128-
}
129-
130125
let hooks = JsPlugin::get_compilation_hooks(compilation.id());
131126
let chunk = compilation.chunk_by_ukey.expect_get(chunk_ukey);
132127
let base_chunk_output_name = get_chunk_output_name(chunk, compilation).await?;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Case module-chunk-css: Step 0
2+
3+
## Changed Files
4+
5+
6+
## Asset Files
7+
8+
9+
## Manifest
10+
11+
12+
## Update
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Case module-chunk-css: Step 1
2+
3+
## Changed Files
4+
- style.module.css
5+
6+
## Asset Files
7+
8+
9+
## Manifest
10+
11+
12+
## Update
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import * as styles from "./style.module.css";
2+
import update from "../../update.esm";
3+
4+
import.meta.webpackHot.accept(["./style.module.css"])
5+
6+
it("should work", async function (done) {
7+
expect(styles).toMatchObject({ class: "_style_module_css-class" });
8+
let firstFullHash = __webpack_hash__;
9+
10+
NEXT(update(done, true, () => {
11+
try{
12+
// only css change should also trigger changing full hash in runtime
13+
expect(__webpack_hash__).not.toBe(firstFullHash);
14+
done();
15+
}catch(e){
16+
done(e)
17+
}
18+
}));
19+
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/** @type {import("../../../../").Configuration} */
2+
module.exports = {
3+
mode: "development",
4+
experiments: {
5+
outputModule: true,
6+
css: true
7+
},
8+
output: {
9+
module: true,
10+
chunkFormat: "module",
11+
filename: "[name].mjs",
12+
chunkFilename: "[name].chunk.mjs",
13+
enabledLibraryTypes: ["module"]
14+
},
15+
optimization: {
16+
minimize: false,
17+
runtimeChunk: "single"
18+
}
19+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.class {
2+
color: red;
3+
}
4+
---
5+
.class-other {
6+
color: blue;
7+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
moduleScope(scope) {
3+
const link = scope.window.document.createElement("link");
4+
link.rel = "stylesheet";
5+
link.href = "https://test.cases/path/bundle.css";
6+
scope.window.document.head.appendChild(link);
7+
},
8+
documentType: "fake"
9+
};
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export default function update(done, options, callback) {
2+
return function (err, stats) {
3+
if (err) return done(err);
4+
import.meta.webpackHot
5+
.check(options || true)
6+
.then(updatedModules => {
7+
if (!updatedModules) {
8+
return done(new Error("No update available"));
9+
}
10+
if (callback) callback(stats);
11+
})
12+
.catch(err => {
13+
done(err);
14+
});
15+
};
16+
};

0 commit comments

Comments
 (0)