Skip to content

Commit

Permalink
fix(mf): should not have extra empty chunk (#5128)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahabhgk authored and IWANABETHATGUY committed Dec 27, 2023
1 parent feece8e commit ea6953f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use std::sync::Arc;
use async_trait::async_trait;
use rspack_core::rspack_sources::BoxSource;
use rspack_core::{
get_js_chunk_filename_template, AdditionalChunkRuntimeRequirementsArgs, ChunkHashArgs, ChunkKind,
CompilationArgs, CompilationParams, CompilerOptions, DependencyType, ErrorSpan,
IgnoreErrorModuleFactory, ModuleType, ParserAndGenerator, PathData, Plugin,
PluginAdditionalChunkRuntimeRequirementsOutput, PluginChunkHashHookOutput,
get_js_chunk_filename_template, AdditionalChunkRuntimeRequirementsArgs, ChunkGraph,
ChunkHashArgs, ChunkKind, ChunkUkey, CompilationArgs, CompilationParams, CompilerOptions,
DependencyType, ErrorSpan, IgnoreErrorModuleFactory, ModuleGraph, ModuleType, ParserAndGenerator,
PathData, Plugin, PluginAdditionalChunkRuntimeRequirementsOutput, PluginChunkHashHookOutput,
PluginCompilationHookOutput, PluginContext, PluginRenderManifestHookOutput, RenderManifestEntry,
RuntimeGlobals, SelfModuleFactory, SourceType,
};
Expand Down Expand Up @@ -252,6 +252,13 @@ impl Plugin for JsPlugin {
} else if chunk.has_runtime(&compilation.chunk_group_by_ukey) {
self.render_main(&args).await?
} else {
if !chunk_has_js(
&args.chunk_ukey,
&compilation.chunk_graph,
&compilation.module_graph,
) {
return Ok(vec![]);
}
self.render_chunk_impl(&args).await?
};

Expand Down Expand Up @@ -306,3 +313,14 @@ pub struct ExtractedCommentsInfo {
pub source: BoxSource,
pub comments_file_name: String,
}

fn chunk_has_js(chunk: &ChunkUkey, chunk_graph: &ChunkGraph, module_graph: &ModuleGraph) -> bool {
if chunk_graph.get_number_of_entry_modules(chunk) > 0 {
true
} else {
chunk_graph
.get_chunk_modules_iterable_by_source_type(chunk, SourceType::JavaScript, module_graph)
.next()
.is_some()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ it("should have good module ids", async () => {
"./b.js",
"./modules-from-remote.js",
"./modules.js",
"./shared.js", // remove this line once concatenateModules is supported https://github.com/web-infra-dev/rspack/issues/3823
"webpack/container/entry/container-no-shared",
"webpack/container/reference/container-with-shared",
"webpack/container/remote/container-with-shared/b",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const { FilteredStatus } = require("../../../lib/util/filterUtil")

module.exports = () => {return [FilteredStatus.PARTIAL_PASS, "Emit detect version warning"]}
// this test depend on 1-container-full
module.exports = () => {return [FilteredStatus.PARTIAL_PASS, "https://github.com/web-infra-dev/rspack/issues/4784"]}

0 comments on commit ea6953f

Please sign in to comment.