Skip to content

Commit

Permalink
fix: modify css loading runtime panic (#8475)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahabhgk authored Nov 19, 2024
1 parent a124d73 commit 522c39e
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
3 changes: 1 addition & 2 deletions crates/rspack_plugin_extract_css/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,7 @@ fn runtime_requirement_in_tree(
|_| false,
move |chunk, compilation| {
chunk
.content_hash(&compilation.chunk_hashes_results)
.expect("should have content hash")
.content_hash(&compilation.chunk_hashes_results)?
.contains_key(&SOURCE_TYPE[0])
.then(|| {
if chunk.can_be_initial(&compilation.chunk_group_by_ukey) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.a {
color: red;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
it("should modify runtime module source in main", async () => {
await import("./index.css");
expect(__webpack_require__.f.miniCss.test).toBeTruthy();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const webpack = require("@rspack/core");

class Plugin {
apply(compiler) {
compiler.hooks.compilation.tap("TestFakePlugin", compilation => {
compilation.hooks.runtimeModule.tap("TestFakePlugin", (module, chunk) => {
if (module.constructorName === "CssLoadingRuntimeModule") {
const originSource = module.source.source.toString("utf-8");
module.source.source = Buffer.from(
`${originSource}\n__webpack_require__.f.miniCss.test = true;\n`,
"utf-8"
);
}
});
});
}
}

/**@type {import("@rspack/core").Configuration}*/
module.exports = {
target: "web",
module: {
rules: [
{
test: /\.css$/,
use: [webpack.CssExtractRspackPlugin.loader, "css-loader"],
type: "javascript/auto"
}
]
},
plugins: [
new webpack.CssExtractRspackPlugin(),
new Plugin(),
]
};

2 comments on commit 522c39e

@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 ✅ success
devserver ✅ success
nuxt ✅ 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-19 bf83b48) Current Change
10000_big_production-mode_disable-minimize + exec 39.8 s ± 1.09 s 40.2 s ± 490 ms +0.86 %
10000_development-mode + exec 1.84 s ± 44 ms 1.8 s ± 26 ms -2.47 %
10000_development-mode_hmr + exec 644 ms ± 10 ms 638 ms ± 7.2 ms -0.93 %
10000_production-mode + exec 2.44 s ± 24 ms 2.38 s ± 26 ms -2.51 %
arco-pro_development-mode + exec 1.8 s ± 69 ms 1.78 s ± 77 ms -0.57 %
arco-pro_development-mode_hmr + exec 430 ms ± 1.5 ms 429 ms ± 1.1 ms -0.33 %
arco-pro_production-mode + exec 3.17 s ± 62 ms 3.13 s ± 77 ms -1.17 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 3.2 s ± 43 ms 3.16 s ± 69 ms -1.20 %
threejs_development-mode_10x + exec 1.57 s ± 16 ms 1.58 s ± 22 ms +0.51 %
threejs_development-mode_10x_hmr + exec 778 ms ± 6.1 ms 778 ms ± 8.2 ms -0.04 %
threejs_production-mode_10x + exec 4.97 s ± 37 ms 4.93 s ± 34 ms -0.73 %

Please sign in to comment.