Skip to content

[turbopack] Create a chunk_group_bootstrap_params() function#94631

Open
sampoder wants to merge 1 commit into
sp-turbopack-shared-runtime-assetfrom
sp/turbopack/registration_code_method
Open

[turbopack] Create a chunk_group_bootstrap_params() function#94631
sampoder wants to merge 1 commit into
sp-turbopack-shared-runtime-assetfrom
sp/turbopack/registration_code_method

Conversation

@sampoder

@sampoder sampoder commented Jun 9, 2026

Copy link
Copy Markdown
Member

This method generates the params for this code (random example for reference):

(globalThis["TURBOPACK"] || (globalThis["TURBOPACK"] = [])).push([
    "output/1ece_tests_snapshot_basic-tree-shake_export-namespace_input_index_0tbr8qy.js",
    {"otherChunks":["output/0_9x_turbopack-tests_tests_snapshot_basic-tree-shake_export-namespace_input_1mqgz2-._.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/basic-tree-shake/export-namespace/input/index.js [test] (ecmascript)"]}
]);

This is a pretty small change on its own (no functionality change), it makes it a separate method so that it can be called in future PRs. I will flag that the shape for inline-d bootstrap code will be slightly different (further up the stack). Because it isn't a chunk itself it does not have the first item in the array (output/1ece_tests_snapshot_basic-tree-shake_export-namespace_input_index_0tbr8qy.js):

(globalThis["TURBOPACK"] || (globalThis["TURBOPACK"] = [])).push({"otherChunks":["static/chunks/node_modules_react-dom_82bf80._.js","static/chunks/_4f9bce._.js","static/chunks/pages_index_tsx_5a9e._.js"],"runtimeModuleIds":[96168]});

This item only has otherChunks and runtimeModuleIds. New code is added in #94664 to handle this different shape.

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Stats cancelled

Commit: da06b98
View workflow run

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Tests Passed

Commit: da06b98

@sampoder sampoder changed the title sp/turbopack/registration code method [turbopack] Create a registration_code() function Jun 9, 2026
@sampoder sampoder changed the title [turbopack] Create a registration_code() function [turbopack] Create a registration_code() function Jun 9, 2026
@sampoder sampoder changed the title [turbopack] Create a registration_code() function [turbopack] Create a registration_code() method Jun 9, 2026
@sampoder sampoder force-pushed the sp/turbopack/registration_code_method branch 2 times, most recently from 58512bf to 0ce9422 Compare June 10, 2026 18:48
@sampoder sampoder changed the title [turbopack] Create a registration_code() method [turbopack] Create a chunk_group_bootstrap_code() function Jun 10, 2026
@sampoder sampoder marked this pull request as ready for review June 10, 2026 18:53
@sampoder sampoder requested review from bgw and lukesandberg June 10, 2026 18:53
@sampoder sampoder force-pushed the sp/turbopack/registration_code_method branch from 0ce9422 to da06b98 Compare June 10, 2026 21:40
@sampoder sampoder changed the title [turbopack] Create a chunk_group_bootstrap_code() function [turbopack] Create a chunk_group_bootstrap_params() function Jun 10, 2026
Comment on lines +153 to +169
let statement = formatdoc! {
r#"
(globalThis[{chunk_loading_global}] || (globalThis[{chunk_loading_global}] = [])).push([
{script_or_path},
{params}
]);
"#,
chunk_loading_global = StringifyJs(&chunk_loading_global),
params = StringifyJs(&params),
)?;
script_or_path = script_or_path,
params = &**params,
};

let mut code = CodeBuilder::new(
source_maps,
*this.chunking_context.debug_ids_enabled().await?,
);
write!(code, "{}", statement)?;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not sure why this got changed from writedoc! to formatdoc!+write!?

Suggested change
let statement = formatdoc! {
r#"
(globalThis[{chunk_loading_global}] || (globalThis[{chunk_loading_global}] = [])).push([
{script_or_path},
{params}
]);
"#,
chunk_loading_global = StringifyJs(&chunk_loading_global),
params = StringifyJs(&params),
)?;
script_or_path = script_or_path,
params = &**params,
};
let mut code = CodeBuilder::new(
source_maps,
*this.chunking_context.debug_ids_enabled().await?,
);
write!(code, "{}", statement)?;
let mut code = CodeBuilder::new(
source_maps,
*this.chunking_context.debug_ids_enabled().await?,
);
writedoc! {
code,
r#"
(globalThis[{chunk_loading_global}] || (globalThis[{chunk_loading_global}] = [])).push([
{script_or_path},
{params}
]);
"#,
chunk_loading_global = StringifyJs(&chunk_loading_global),
script_or_path = script_or_path,
params = &**params,
}?;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants