Skip to content

Commit 319353e

Browse files
mischniceps1lon
authored andcommitted
Turbopack: leave chunks in rscModuleMapping empty (#79511)
Previously, `clientReferenceManifest.rscModuleMapping.*.chunks` would list the RSC entry, such as `server/app/encryption/page.js` which contains ```js const CHUNK_PUBLIC_PATH = "server/app/encryption/page.js"; const runtime = require("../../chunks/ssr/[turbopack]_runtime.js"); runtime.loadChunk("server/chunks/ssr/[root-of-the-server]__a810eacb._.js"); runtime.loadChunk("server/chunks/ssr/_7a4bd82c._.js"); runtime.loadChunk("server/chunks/ssr/test_e2e_app-dir_actions_app_not-found_b8caa540.js"); runtime.loadChunk("server/chunks/ssr/packages_next_dist_client_components_1d957a03._.js"); runtime.loadChunk("server/chunks/ssr/packages_next_dist_client_components_unauthorized-error_4ad694c5.js"); runtime.loadChunk("server/chunks/ssr/_0aa93936._.js"); runtime.getOrInstantiateRuntimeModule("[project]/test/e2e/app-dir/actions/.next-internal/server/app/encryption/page/actions.js { ACTIONS_MODULE0 => \"[project]/test/e2e/app-dir/actions/app/encryption/page.js [app-rsc] (ecmascript)\" } [app-rsc] (server actions loader, ecmascript)", CHUNK_PUBLIC_PATH); runtime.getOrInstantiateRuntimeModule("[project]/packages/next/dist/esm/build/templates/app-page.js??page=/encryption/page { MODULE_0 => \"[project]/test/e2e/app-dir/actions/app/layout.js [app-rsc] (ecmascript, Next.js Server Component)\", MODULE_1 => \"[project]/test/e2e/app-dir/actions/app/not-found.js [app-rsc] (ecmascript, Next.js Server Component)\", MODULE_2 => \"[project]/packages/next/dist/client/components/forbidden-error.js [app-rsc] (ecmascript, Next.js Server Component)\", MODULE_3 => \"[project]/packages/next/dist/client/components/unauthorized-error.js [app-rsc] (ecmascript, Next.js Server Component)\", MODULE_4 => \"[project]/test/e2e/app-dir/actions/app/encryption/page.js [app-rsc] (ecmascript, Next.js Server Component)\" } [app-rsc] (ecmascript)", CHUNK_PUBLIC_PATH); module.exports = runtime.getOrInstantiateRuntimeModule("[project]/packages/next/dist/esm/build/templates/app-page.js??page=/encryption/page { MODULE_0 => \"[project]/test/e2e/app-dir/actions/app/layout.js [app-rsc] (ecmascript, Next.js Server Component)\", MODULE_1 => \"[project]/test/e2e/app-dir/actions/app/not-found.js [app-rsc] (ecmascript, Next.js Server Component)\", MODULE_2 => \"[project]/packages/next/dist/client/components/forbidden-error.js [app-rsc] (ecmascript, Next.js Server Component)\", MODULE_3 => \"[project]/packages/next/dist/client/components/unauthorized-error.js [app-rsc] (ecmascript, Next.js Server Component)\", MODULE_4 => \"[project]/test/e2e/app-dir/actions/app/encryption/page.js [app-rsc] (ecmascript, Next.js Server Component)\" } [app-rsc] (ecmascript)", CHUNK_PUBLIC_PATH).exports; ``` The problem is that this chunk (Turbopack calls them "entry chunk") exports some entry point, as opposed to the usual chunk which does `module.exports = {19285: function(){}, ...}` to export the module factories (called an "evaluated chunk") If you use `__turbopack_load__` to load an entry chunk, stuff breaks because you end up with the entry module's exports in the module factory map. Hendrik confirmed that Webpack also doesn't specify any chunks in here, they are already loaded anyway. Then this case of `__turbopack_load__`ing an entry chunk never occurs.
1 parent a4e23b4 commit 319353e

File tree

2 files changed

+5
-35
lines changed

2 files changed

+5
-35
lines changed

crates/next-api/src/app.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1459,7 +1459,6 @@ impl AppEndpoint {
14591459
entry_name: app_entry.original_name.clone(),
14601460
client_references,
14611461
client_references_chunks,
1462-
rsc_app_entry_chunks: app_entry_chunks,
14631462
client_chunking_context,
14641463
ssr_chunking_context,
14651464
async_module_info: module_graphs.full.async_module_info().to_resolved().await?,

crates/next-core/src/next_manifests/client_reference_manifest.rs

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use turbopack_core::{
1515
asset::{Asset, AssetContent},
1616
chunk::{ChunkingContext, ModuleChunkItemIdExt, ModuleId as TurbopackModuleId},
1717
module_graph::async_module_info::AsyncModulesInfo,
18-
output::{OutputAsset, OutputAssets},
18+
output::OutputAsset,
1919
virtual_output::VirtualOutputAsset,
2020
};
2121
use turbopack_ecmascript::utils::StringifyJs;
@@ -37,7 +37,6 @@ pub struct ClientReferenceManifestOptions {
3737
pub entry_name: RcStr,
3838
pub client_references: ResolvedVc<ClientReferenceGraphResult>,
3939
pub client_references_chunks: ResolvedVc<ClientReferencesChunks>,
40-
pub rsc_app_entry_chunks: ResolvedVc<OutputAssets>,
4140
pub client_chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
4241
pub ssr_chunking_context: Option<ResolvedVc<Box<dyn ChunkingContext>>>,
4342
pub async_module_info: ResolvedVc<AsyncModulesInfo>,
@@ -58,7 +57,6 @@ impl ClientReferenceManifest {
5857
entry_name,
5958
client_references,
6059
client_references_chunks,
61-
rsc_app_entry_chunks,
6260
client_chunking_context,
6361
ssr_chunking_context,
6462
async_module_info,
@@ -100,7 +98,6 @@ impl ClientReferenceManifest {
10098
} = &*client_references_chunks.await?;
10199
let client_relative_path = &*client_relative_path.await?;
102100
let node_root_ref = &*node_root.await?;
103-
let rsc_app_entry_chunks = &*rsc_app_entry_chunks.await?;
104101

105102
let client_references_ecmascript = client_references
106103
.await?
@@ -167,10 +164,6 @@ impl ClientReferenceManifest {
167164
ResolvedVc<Box<dyn OutputAsset>>,
168165
ReadRef<FileSystemPath>,
169166
> = FxHashMap::default();
170-
let mut rsc_chunk_path_cache: FxHashMap<
171-
ResolvedVc<Box<dyn OutputAsset>>,
172-
ReadRef<FileSystemPath>,
173-
> = FxHashMap::default();
174167

175168
for (client_reference_module, client_reference_module_ref) in
176169
client_references_ecmascript
@@ -266,32 +259,10 @@ impl ClientReferenceManifest {
266259
(Vec::new(), false)
267260
};
268261

269-
let (rsc_chunks_paths, rsc_is_async) = if runtime == NextRuntime::Edge {
270-
// the chunks get added to the middleware-manifest.json instead
271-
// of this file because the
272-
// edge runtime doesn't support dynamically
273-
// loading chunks.
274-
(Vec::new(), false)
262+
let rsc_is_async = if runtime == NextRuntime::Edge {
263+
false
275264
} else {
276-
let rsc_chunks_paths = cached_chunk_paths(
277-
&mut rsc_chunk_path_cache,
278-
rsc_app_entry_chunks.iter().copied(),
279-
)
280-
.await?;
281-
282-
let chunk_paths = rsc_chunks_paths
283-
.filter_map(|(_, chunk_path)| {
284-
node_root_ref
285-
.get_path_to(&chunk_path)
286-
.map(ToString::to_string)
287-
})
288-
.map(RcStr::from)
289-
.collect::<Vec<_>>();
290-
291-
let is_async =
292-
async_modules.contains(&ResolvedVc::upcast(client_reference_module));
293-
294-
(chunk_paths, is_async)
265+
async_modules.contains(&ResolvedVc::upcast(client_reference_module))
295266
};
296267

297268
entry_manifest.client_modules.module_exports.insert(
@@ -326,7 +297,7 @@ impl ClientReferenceManifest {
326297
ManifestNodeEntry {
327298
name: "*".into(),
328299
id: (&*rsc_chunk_item_id).into(),
329-
chunks: rsc_chunks_paths,
300+
chunks: vec![],
330301
r#async: rsc_is_async,
331302
},
332303
);

0 commit comments

Comments
 (0)