Skip to content

Commit

Permalink
Turbopack: switch to a single client components entrypoint (#59352)
Browse files Browse the repository at this point in the history
### What?

switch turbopack to use a single client components entrypoint for all
client components on a page for development. This aligns it with the
webpack behavior.

### Why?

compiling a separate entrypoint for every client component is pretty
expensive in regards of compilation, chunking, code generation, file
writing and number of requests.

### Turbopack Changes

* vercel/turborepo#6713 <!-- Tobias Koppers - use
real emojis -->
* vercel/turborepo#6728 <!-- Tobias Koppers - fix
order of reverse topologic iteration -->


Closes PACK-2115
  • Loading branch information
sokra authored Dec 8, 2023
1 parent f7b9843 commit 26b8caa
Show file tree
Hide file tree
Showing 17 changed files with 399 additions and 93 deletions.
68 changes: 34 additions & 34 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ swc_core = { version = "0.86.81", features = [
testing = { version = "0.35.11" }

# Turbo crates
turbopack-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-231206.4" }
turbopack-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-231207.2" }
# [TODO]: need to refactor embed_directory! macro usages, as well as resolving turbo_tasks::function, macros..
turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-231206.4" }
turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-231207.2" }
# [TODO]: need to refactor embed_directory! macro usage in next-core
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-231206.4" }
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-231207.2" }

# General Deps

Expand Down
15 changes: 8 additions & 7 deletions packages/next-swc/crates/next-api/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,7 @@ impl AppEndpoint {
};

let client_references_chunks = get_app_client_references_chunks(
app_entry.rsc_entry.ident(),
client_reference_types,
this.app_project.project().client_chunking_context(),
ssr_chunking_context,
Expand All @@ -637,7 +638,7 @@ impl AppEndpoint {
for client_reference in app_entry_client_references.iter() {
let client_reference_chunks = client_references_chunks_ref
.get(client_reference.ty())
.expect("client reference should have corresponding chunks");
.context("client reference should have corresponding chunks")?;
entry_client_chunks
.extend(client_reference_chunks.client_chunks.await?.iter().copied());
entry_ssr_chunks.extend(client_reference_chunks.ssr_chunks.await?.iter().copied());
Expand All @@ -651,15 +652,15 @@ impl AppEndpoint {
.map(|chunk| chunk.ident().path())
.try_join()
.await?;
let mut entry_client_chunks_paths: Vec<_> = entry_client_chunks_paths
let mut entry_client_chunks_paths = entry_client_chunks_paths
.iter()
.map(|path| {
client_relative_path_ref
Ok(client_relative_path_ref
.get_path_to(path)
.expect("asset path should be inside client root")
.to_string()
.context("asset path should be inside client root")?
.to_string())
})
.collect();
.collect::<anyhow::Result<Vec<_>>>()?;
entry_client_chunks_paths.extend(client_shared_chunks_paths.iter().cloned());

let app_build_manifest = AppBuildManifest {
Expand Down Expand Up @@ -997,7 +998,7 @@ impl AppEndpoint {
server_path
.await?
.get_path_to(&*rsc_chunk.ident().path().await?)
.expect("RSC chunk path should be within app paths manifest directory")
.context("RSC chunk path should be within app paths manifest directory")?
.to_string(),
)?;
server_assets.push(app_paths_manifest_output);
Expand Down
2 changes: 2 additions & 0 deletions packages/next-swc/crates/next-build/src/next_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use turbopack_binding::{
core::{
asset::Asset,
environment::ServerAddr,
ident::AssetIdent,
issue::{handle_issues, IssueReporter, IssueSeverity},
output::{OutputAsset, OutputAssets},
virtual_fs::VirtualFileSystem,
Expand Down Expand Up @@ -309,6 +310,7 @@ pub(crate) async fn next_build(options: TransientInstance<BuildOptions>) -> Resu
// APP CLIENT REFERENCES CHUNKING

let app_client_references_chunks = get_app_client_references_chunks(
AssetIdent::from_path(project_root.join("next-client-components.js".to_string())),
app_client_reference_tys,
client_chunking_context,
// TODO(WEB-1824): add edge support
Expand Down
Loading

0 comments on commit 26b8caa

Please sign in to comment.