Skip to content

Commit

Permalink
fix: hotUpdate chunk should have correct runtime (#8273)
Browse files Browse the repository at this point in the history
  • Loading branch information
JSerFeng authored Nov 1, 2024
1 parent af15a3f commit 2020005
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 1 deletion.
6 changes: 5 additions & 1 deletion crates/rspack_plugin_hmr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,11 @@ async fn process_assets(&self, compilation: &mut Compilation) -> Result<()> {
if !new_modules.is_empty() || !new_runtime_modules.is_empty() {
let mut hot_update_chunk = Chunk::new(None, ChunkKind::HotUpdate);
hot_update_chunk.id = Some(chunk_id.to_string());
hot_update_chunk.runtime = new_runtime.clone();
hot_update_chunk.runtime = if let Some(current_chunk) = current_chunk {
current_chunk.runtime.clone()
} else {
new_runtime.clone()
};
let ukey = hot_update_chunk.ukey;

if let Some(current_chunk) = current_chunk {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
let value = require("./module.js");
import {a} from "./lib/a.js";

it("should compile", (done) => {
expect(value).toBe(1);
expect(a).toBe(1);
module.hot.accept("./module.js", () => {
value = require("./module");
expect(value).toBe(2);
done();
});
NEXT(require("../../update")(done));
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const a = 1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const b = 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"sideEffects": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = 1;
---
new Worker(new URL('./worker.js', import.meta.url))
module.exports = 2;
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = {
optimization: {
usedExports: true,
// make 'lib' chunk runtime to be worker + entry
splitChunks: {
minSize: 0,
chunks: "all",
cacheGroups: {
lib: {
test: /[/\\]lib[/\\](a|b|index).js$/,
name: "lib",
filename: "bundle-lib.js"
}
}
}
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = function (config) {
if (config.target !== "web") {
return false;
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import {b} from "./lib/b.js";
b;

2 comments on commit 2020005

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Ran ecosystem CI: Open

suite result
modernjs ✅ success
_selftest ✅ success
rspress ✅ success
rslib ✅ success
rsbuild ✅ success
examples ❌ failure
devserver ✅ success

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Benchmark detail: Open

Name Base (2024-11-01 4aeee85) Current Change
10000_big_production-mode + exec 47.5 s ± 1.45 s 48.1 s ± 1.03 s +1.18 %
10000_development-mode + exec 2.08 s ± 13 ms 2.08 s ± 32 ms +0.13 %
10000_development-mode_hmr + exec 649 ms ± 13 ms 647 ms ± 10 ms -0.42 %
10000_production-mode + exec 2.62 s ± 29 ms 2.64 s ± 35 ms +0.62 %
arco-pro_development-mode + exec 1.78 s ± 79 ms 1.78 s ± 58 ms +0.33 %
arco-pro_development-mode_hmr + exec 428 ms ± 1.1 ms 428 ms ± 2.6 ms -0.06 %
arco-pro_production-mode + exec 3.22 s ± 82 ms 3.21 s ± 39 ms -0.18 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 3.22 s ± 79 ms 3.25 s ± 40 ms +0.90 %
threejs_development-mode_10x + exec 1.64 s ± 12 ms 1.66 s ± 14 ms +1.21 %
threejs_development-mode_10x_hmr + exec 784 ms ± 14 ms 779 ms ± 9.1 ms -0.56 %
threejs_production-mode_10x + exec 5.03 s ± 52 ms 5.02 s ± 29 ms -0.16 %

Please sign in to comment.