Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include chunk path in WithClientChunks #3910

Merged
merged 2 commits into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 23 additions & 16 deletions crates/next-core/src/next_client_component/with_client_chunks.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::Result;
use serde_json::Value;
use indoc::formatdoc;
use turbo_tasks::{primitives::StringVc, ValueToString, ValueToStringVc};
use turbo_tasks_fs::FileSystemPathVc;
use turbopack::ecmascript::{
Expand Down Expand Up @@ -116,31 +116,38 @@ impl EcmascriptChunkItem for WithClientChunksChunkItem {
let group = ChunkGroupVc::from_asset(inner.asset.into(), self.context);
let chunks = group.chunks().await?;
let server_root = inner.server_root.await?;
let mut client_chunks = Vec::new();

let mut asset_paths = vec![];
for chunk in chunks.iter() {
for reference in chunk.references().await?.iter() {
let assets = &*reference.resolve_reference().primary_assets().await?;
for asset in assets.iter() {
let path = &*asset.path().await?;

// only client chunks have an path from the server root
if let Some(path) = server_root.get_path_to(path) {
client_chunks.push(Value::String(path.to_string()));
}
asset_paths.push(asset.path().await?);
}
}

asset_paths.push(chunk.path().await?);
}

let mut client_chunks = Vec::new();
for asset_path in asset_paths {
if let Some(path) = server_root.get_path_to(&asset_path) {
client_chunks.push(path.to_string());
}
}

let module_id = stringify_js(&*inner.asset.as_chunk_item(self.context).id().await?);
Ok(EcmascriptChunkItemContent {
inner_code: format!(
"__turbopack_esm__({{
default: () => __turbopack_import__({}),
chunks: () => chunks
}});
const chunks = {};
",
inner_code: formatdoc!(
r#"
__turbopack_esm__({{
default: () => __turbopack_import__({}),
chunks: () => chunks
}});
const chunks = {};
"#,
module_id,
Value::Array(client_chunks)
stringify_js(&client_chunks)
)
.into(),
..Default::default()
Expand Down
26 changes: 12 additions & 14 deletions crates/turbo-tasks-memory/src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ impl Task {
}) => {
// Connect the task to the current task. This makes strongly consistent behaving
// as expected and we can look up the collectibles in the current scope.
self.connect_child_internal(state, task_id, backend, &*turbo_tasks);
self.connect_child_internal(state, task_id, backend, turbo_tasks);
// state was dropped by previous method
Box::pin(Self::execute_read_task_collectibles(
self.id,
Expand Down Expand Up @@ -1222,18 +1222,16 @@ impl Task {
*optimization_counter += 1;
if merging_scopes > 0 {
*optimization_counter = optimization_counter.saturating_sub(merging_scopes);
} else {
if should_optimize_to_root_scoped(*optimization_counter, children.len()) {
list.remove(id);
drop(self.make_root_scoped_internal(state, backend, turbo_tasks));
return self.add_to_scope_internal_shallow(
id,
merging_scopes,
backend,
turbo_tasks,
queue,
);
}
} else if should_optimize_to_root_scoped(*optimization_counter, children.len()) {
list.remove(id);
drop(self.make_root_scoped_internal(state, backend, turbo_tasks));
return self.add_to_scope_internal_shallow(
id,
merging_scopes,
backend,
turbo_tasks,
queue,
);
}

if queue.capacity() == 0 {
Expand Down Expand Up @@ -2132,7 +2130,7 @@ impl Task {
let backend = turbo_tasks.backend();
backend.with_task(task_id, |task| {
let state =
task.ensure_root_scoped(task.full_state_mut(), backend, &*turbo_tasks);
task.ensure_root_scoped(task.full_state_mut(), backend, turbo_tasks);
if let TaskScopes::Root(scope_id) = state.scopes {
backend.with_scope(scope_id, |scope| {
scope.read_collectibles_and_children(
Expand Down