Unverified Commit 10dbcc6f authored by Alex Kirszenberg's avatar Alex Kirszenberg Committed by GitHub

ChunkingContext refactor pt. 1 (#47693)

This is the Next.js side of https://github.com/vercel/turbo/pull/4397

---------
Co-authored-by: 's avatarTobias Koppers <tobias.koppers@googlemail.com>
Co-authored-by: 's avatarkodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
parent 199aa3c8
This diff is collapsed.
...@@ -47,11 +47,11 @@ swc_emotion = { version = "0.29.10" } ...@@ -47,11 +47,11 @@ swc_emotion = { version = "0.29.10" }
testing = { version = "0.31.31" } testing = { version = "0.31.31" }
# Turbo crates # Turbo crates
turbo-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230404.3" } turbo-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230404.4" }
# [TODO]: need to refactor embed_directory! macro usages, as well as resolving turbo_tasks::function, macros.. # [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-230404.3" } turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230404.4" }
# [TODO]: need to refactor embed_directory! macro usage in next-core # [TODO]: need to refactor embed_directory! macro usage in next-core
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230404.3" } turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230404.4" }
# General Deps # General Deps
......
...@@ -5,13 +5,17 @@ use async_recursion::async_recursion; ...@@ -5,13 +5,17 @@ use async_recursion::async_recursion;
use indexmap::{indexmap, IndexMap}; use indexmap::{indexmap, IndexMap};
use turbo_binding::{ use turbo_binding::{
turbo::{ turbo::{
tasks::{primitives::OptionStringVc, Value}, tasks::{
primitives::{OptionStringVc, StringVc},
Value,
},
tasks_env::{CustomProcessEnvVc, EnvMapVc, ProcessEnvVc}, tasks_env::{CustomProcessEnvVc, EnvMapVc, ProcessEnvVc},
tasks_fs::{rope::RopeBuilder, File, FileContent, FileSystemPathVc}, tasks_fs::{rope::RopeBuilder, File, FileContent, FileSystemPathVc},
}, },
turbopack::{ turbopack::{
core::{ core::{
asset::{AssetVc, AssetsVc}, asset::{AssetVc, AssetsVc},
chunk::{EvaluatableAssetVc, EvaluatableAssetsVc},
compile_time_info::CompileTimeInfoVc, compile_time_info::CompileTimeInfoVc,
context::{AssetContext, AssetContextVc}, context::{AssetContext, AssetContextVc},
environment::{EnvironmentIntention, ServerAddrVc}, environment::{EnvironmentIntention, ServerAddrVc},
...@@ -50,7 +54,6 @@ use turbo_binding::{ ...@@ -50,7 +54,6 @@ use turbo_binding::{
}, },
}, },
}; };
use turbo_tasks::primitives::StringVc;
use crate::{ use crate::{
app_render::next_layout_entry_transition::NextServerComponentTransition, app_render::next_layout_entry_transition::NextServerComponentTransition,
...@@ -394,7 +397,10 @@ pub async fn create_app_source( ...@@ -394,7 +397,10 @@ pub async fn create_app_source(
let injected_env = env_for_js(EnvMapVc::empty().into(), false, next_config); let injected_env = env_for_js(EnvMapVc::empty().into(), false, next_config);
let env = CustomProcessEnvVc::new(env, next_config.env()).as_process_env(); let env = CustomProcessEnvVc::new(env, next_config.env()).as_process_env();
let server_runtime_entries = vec![ProcessEnvAssetVc::new(project_path, injected_env).into()]; let server_runtime_entries =
AssetsVc::cell(vec![
ProcessEnvAssetVc::new(project_path, injected_env).into()
]);
let fallback_page = get_fallback_page( let fallback_page = get_fallback_page(
project_path, project_path,
...@@ -405,8 +411,6 @@ pub async fn create_app_source( ...@@ -405,8 +411,6 @@ pub async fn create_app_source(
next_config, next_config,
); );
let server_runtime_entries = AssetsVc::cell(server_runtime_entries);
let sources = entrypoints let sources = entrypoints
.await? .await?
.iter() .iter()
...@@ -468,6 +472,7 @@ async fn create_app_page_source_for_route( ...@@ -468,6 +472,7 @@ async fn create_app_page_source_for_route(
params_matcher.into(), params_matcher.into(),
pathname_vc, pathname_vc,
AppRenderer { AppRenderer {
runtime_entries,
context_ssr, context_ssr,
context, context,
server_root, server_root,
...@@ -477,7 +482,6 @@ async fn create_app_page_source_for_route( ...@@ -477,7 +482,6 @@ async fn create_app_page_source_for_route(
} }
.cell() .cell()
.into(), .into(),
runtime_entries,
fallback_page, fallback_page,
); );
...@@ -510,6 +514,7 @@ async fn create_app_route_source_for_route( ...@@ -510,6 +514,7 @@ async fn create_app_route_source_for_route(
pathname_vc, pathname_vc,
AppRoute { AppRoute {
context: context_ssr, context: context_ssr,
runtime_entries,
server_root, server_root,
entry_path, entry_path,
project_path, project_path,
...@@ -518,7 +523,6 @@ async fn create_app_route_source_for_route( ...@@ -518,7 +523,6 @@ async fn create_app_route_source_for_route(
} }
.cell() .cell()
.into(), .into(),
runtime_entries,
); );
Ok(source.issue_context(app_dir, &format!("Next.js App Route {pathname}"))) Ok(source.issue_context(app_dir, &format!("Next.js App Route {pathname}")))
...@@ -527,6 +531,7 @@ async fn create_app_route_source_for_route( ...@@ -527,6 +531,7 @@ async fn create_app_route_source_for_route(
/// The renderer for pages in app directory /// The renderer for pages in app directory
#[turbo_tasks::value] #[turbo_tasks::value]
struct AppRenderer { struct AppRenderer {
runtime_entries: AssetsVc,
context_ssr: AssetContextVc, context_ssr: AssetContextVc,
context: AssetContextVc, context: AssetContextVc,
project_path: FileSystemPathVc, project_path: FileSystemPathVc,
...@@ -540,6 +545,7 @@ impl AppRendererVc { ...@@ -540,6 +545,7 @@ impl AppRendererVc {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn entry(self, is_rsc: bool) -> Result<NodeRenderingEntryVc> { async fn entry(self, is_rsc: bool) -> Result<NodeRenderingEntryVc> {
let AppRenderer { let AppRenderer {
runtime_entries,
context_ssr, context_ssr,
context, context,
project_path, project_path,
...@@ -703,7 +709,13 @@ import {}, {{ chunks as {} }} from "COMPONENT_{}"; ...@@ -703,7 +709,13 @@ import {}, {{ chunks as {} }} from "COMPONENT_{}";
.build(); .build();
Ok(NodeRenderingEntry { Ok(NodeRenderingEntry {
context, runtime_entries: EvaluatableAssetsVc::cell(
runtime_entries
.await?
.iter()
.map(|entry| EvaluatableAssetVc::from_asset(*entry, context))
.collect(),
),
module: EcmascriptModuleAssetVc::new_with_inner_assets( module: EcmascriptModuleAssetVc::new_with_inner_assets(
asset.into(), asset.into(),
context, context,
...@@ -749,6 +761,7 @@ impl NodeEntry for AppRenderer { ...@@ -749,6 +761,7 @@ impl NodeEntry for AppRenderer {
/// The node.js renderer api routes in the app directory /// The node.js renderer api routes in the app directory
#[turbo_tasks::value] #[turbo_tasks::value]
struct AppRoute { struct AppRoute {
runtime_entries: AssetsVc,
context: AssetContextVc, context: AssetContextVc,
entry_path: FileSystemPathVc, entry_path: FileSystemPathVc,
intermediate_output_path: FileSystemPathVc, intermediate_output_path: FileSystemPathVc,
...@@ -784,7 +797,13 @@ impl AppRouteVc { ...@@ -784,7 +797,13 @@ impl AppRouteVc {
Value::new(ReferenceType::Entry(EntryReferenceSubType::AppRoute)), Value::new(ReferenceType::Entry(EntryReferenceSubType::AppRoute)),
); );
Ok(NodeRenderingEntry { Ok(NodeRenderingEntry {
context: this.context, runtime_entries: EvaluatableAssetsVc::cell(
this.runtime_entries
.await?
.iter()
.map(|entry| EvaluatableAssetVc::from_asset(*entry, this.context))
.collect(),
),
module: EcmascriptModuleAssetVc::new_with_inner_assets( module: EcmascriptModuleAssetVc::new_with_inner_assets(
virtual_asset.into(), virtual_asset.into(),
this.context, this.context,
......
...@@ -83,10 +83,12 @@ pub async fn get_fallback_page( ...@@ -83,10 +83,12 @@ pub async fn get_fallback_page(
bail!("fallback runtime entry is not an ecmascript module"); bail!("fallback runtime entry is not an ecmascript module");
}; };
let chunk = module.as_evaluated_chunk(chunking_context, Some(runtime_entries));
Ok(DevHtmlAssetVc::new( Ok(DevHtmlAssetVc::new(
dev_server_root.join("fallback.html"), dev_server_root.join("fallback.html"),
vec![ChunkGroupVc::from_chunk(chunk)], vec![ChunkGroupVc::evaluated(
chunking_context,
module.into(),
runtime_entries,
)],
)) ))
} }
...@@ -3,40 +3,33 @@ use turbo_binding::{ ...@@ -3,40 +3,33 @@ use turbo_binding::{
turbo::{tasks::ValueToString, tasks_fs::FileSystemPathVc}, turbo::{tasks::ValueToString, tasks_fs::FileSystemPathVc},
turbopack::{ turbopack::{
core::{ core::{
asset::{Asset, AssetVc, AssetsVc}, asset::{Asset, AssetVc},
chunk::{EvaluatableAssetVc, EvaluatableAssetsVc},
context::AssetContextVc, context::AssetContextVc,
issue::{IssueSeverity, OptionIssueSourceVc}, issue::{IssueSeverity, OptionIssueSourceVc},
resolve::{origin::PlainResolveOriginVc, parse::RequestVc}, resolve::{origin::PlainResolveOriginVc, parse::RequestVc},
}, },
ecmascript::{ ecmascript::resolve::cjs_resolve,
chunk::{EcmascriptChunkPlaceableVc, EcmascriptChunkPlaceablesVc},
process_runtime_entries,
resolve::cjs_resolve,
},
}, },
}; };
#[turbo_tasks::value(shared)] #[turbo_tasks::value(shared)]
pub enum RuntimeEntry { pub enum RuntimeEntry {
Request(RequestVc, FileSystemPathVc), Request(RequestVc, FileSystemPathVc),
Ecmascript(EcmascriptChunkPlaceableVc), Evaluatable(EvaluatableAssetVc),
Source(AssetVc), Source(AssetVc),
} }
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl RuntimeEntryVc { impl RuntimeEntryVc {
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn resolve_entry( pub async fn resolve_entry(self, context: AssetContextVc) -> Result<EvaluatableAssetsVc> {
self,
context: AssetContextVc,
) -> Result<EcmascriptChunkPlaceablesVc> {
let (request, path) = match *self.await? { let (request, path) = match *self.await? {
RuntimeEntry::Ecmascript(e) => return Ok(EcmascriptChunkPlaceablesVc::cell(vec![e])), RuntimeEntry::Evaluatable(e) => return Ok(EvaluatableAssetsVc::one(e)),
RuntimeEntry::Source(source) => { RuntimeEntry::Source(source) => {
return Ok(process_runtime_entries( return Ok(EvaluatableAssetsVc::one(EvaluatableAssetVc::from_asset(
context, source, context,
AssetsVc::cell(vec![source]), )));
))
} }
RuntimeEntry::Request(r, path) => (r, path), RuntimeEntry::Request(r, path) => (r, path),
}; };
...@@ -52,18 +45,17 @@ impl RuntimeEntryVc { ...@@ -52,18 +45,17 @@ impl RuntimeEntryVc {
let mut runtime_entries = Vec::with_capacity(assets.len()); let mut runtime_entries = Vec::with_capacity(assets.len());
for asset in &assets { for asset in &assets {
if let Some(placeable) = EcmascriptChunkPlaceableVc::resolve_from(asset).await? { if let Some(entry) = EvaluatableAssetVc::resolve_from(asset).await? {
runtime_entries.push(placeable); runtime_entries.push(entry);
} else { } else {
bail!( bail!(
"runtime reference resolved to an asset ({}) that is not placeable into an \ "runtime reference resolved to an asset ({}) that cannot be evaluated",
ecmascript chunk",
asset.ident().to_string().await? asset.ident().to_string().await?
); );
} }
} }
Ok(EcmascriptChunkPlaceablesVc::cell(runtime_entries)) Ok(EvaluatableAssetsVc::cell(runtime_entries))
} }
} }
...@@ -73,10 +65,7 @@ pub struct RuntimeEntries(Vec<RuntimeEntryVc>); ...@@ -73,10 +65,7 @@ pub struct RuntimeEntries(Vec<RuntimeEntryVc>);
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl RuntimeEntriesVc { impl RuntimeEntriesVc {
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn resolve_entries( pub async fn resolve_entries(self, context: AssetContextVc) -> Result<EvaluatableAssetsVc> {
self,
context: AssetContextVc,
) -> Result<EcmascriptChunkPlaceablesVc> {
let mut runtime_entries = Vec::new(); let mut runtime_entries = Vec::new();
for reference in &self.await? { for reference in &self.await? {
...@@ -84,6 +73,6 @@ impl RuntimeEntriesVc { ...@@ -84,6 +73,6 @@ impl RuntimeEntriesVc {
runtime_entries.extend(resolved_entries.into_iter()); runtime_entries.extend(resolved_entries.into_iter());
} }
Ok(EcmascriptChunkPlaceablesVc::cell(runtime_entries)) Ok(EvaluatableAssetsVc::cell(runtime_entries))
} }
} }
...@@ -110,7 +110,6 @@ impl Transition for NextClientChunksTransition { ...@@ -110,7 +110,6 @@ impl Transition for NextClientChunksTransition {
if let Some(placeable) = EcmascriptChunkPlaceableVc::resolve_from(asset).await? { if let Some(placeable) = EcmascriptChunkPlaceableVc::resolve_from(asset).await? {
WithChunksAsset { WithChunksAsset {
asset: placeable, asset: placeable,
server_root: self.server_root,
chunking_context: self.client_chunking_context, chunking_context: self.client_chunking_context,
} }
.cell() .cell()
......
use std::io::Write;
use anyhow::{bail, Result}; use anyhow::{bail, Result};
use indoc::formatdoc; use indoc::writedoc;
use turbo_binding::{ use turbo_binding::{
turbo::{tasks::TryJoinIterExt, tasks_fs::FileSystemPathVc}, turbo::tasks::TryJoinIterExt,
turbopack::{ turbopack::{
core::{ core::{
asset::{Asset, AssetContentVc, AssetVc}, asset::{Asset, AssetContentVc, AssetVc},
chunk::{ chunk::{
availability_info::AvailabilityInfo, Chunk, ChunkGroupReferenceVc, ChunkGroupVc, availability_info::AvailabilityInfo, ChunkGroupReferenceVc, ChunkGroupVc,
ChunkItem, ChunkItemVc, ChunkListReferenceVc, ChunkVc, ChunkableAsset, ChunkItem, ChunkItemVc, ChunkVc, ChunkableAsset, ChunkableAssetVc, ChunkingContext,
ChunkableAssetVc, ChunkingContextVc, ChunkingContextVc,
}, },
ident::AssetIdentVc, ident::AssetIdentVc,
reference::AssetReferencesVc, reference::AssetReferencesVc,
}, },
turbopack::ecmascript::{ dev::{ChunkListReferenceVc, DevChunkingContextVc},
ecmascript::{
chunk::{ chunk::{
EcmascriptChunkItem, EcmascriptChunkItemContent, EcmascriptChunkItemContentVc, EcmascriptChunkItem, EcmascriptChunkItemContent, EcmascriptChunkItemContentVc,
EcmascriptChunkItemVc, EcmascriptChunkPlaceable, EcmascriptChunkPlaceableVc, EcmascriptChunkItemVc, EcmascriptChunkPlaceable, EcmascriptChunkPlaceableVc,
...@@ -25,6 +28,8 @@ use turbo_binding::{ ...@@ -25,6 +28,8 @@ use turbo_binding::{
}, },
}; };
use turbo_tasks::{primitives::StringVc, Value}; use turbo_tasks::{primitives::StringVc, Value};
use turbo_tasks_fs::rope::RopeBuilder;
#[turbo_tasks::function] #[turbo_tasks::function]
fn modifier() -> StringVc { fn modifier() -> StringVc {
StringVc::cell("chunks".to_string()) StringVc::cell("chunks".to_string())
...@@ -33,7 +38,6 @@ fn modifier() -> StringVc { ...@@ -33,7 +38,6 @@ fn modifier() -> StringVc {
#[turbo_tasks::value(shared)] #[turbo_tasks::value(shared)]
pub struct WithChunksAsset { pub struct WithChunksAsset {
pub asset: EcmascriptChunkPlaceableVc, pub asset: EcmascriptChunkPlaceableVc,
pub server_root: FileSystemPathVc,
pub chunking_context: ChunkingContextVc, pub chunking_context: ChunkingContextVc,
} }
...@@ -53,10 +57,17 @@ impl Asset for WithChunksAsset { ...@@ -53,10 +57,17 @@ impl Asset for WithChunksAsset {
async fn references(self_vc: WithChunksAssetVc) -> Result<AssetReferencesVc> { async fn references(self_vc: WithChunksAssetVc) -> Result<AssetReferencesVc> {
let this = self_vc.await?; let this = self_vc.await?;
let chunk_group = self_vc.chunk_group(); let chunk_group = self_vc.chunk_group();
Ok(AssetReferencesVc::cell(vec![
ChunkGroupReferenceVc::new(chunk_group).into(), let mut references = vec![ChunkGroupReferenceVc::new(chunk_group).into()];
ChunkListReferenceVc::new(this.server_root, chunk_group).into(),
])) if let Some(context) = DevChunkingContextVc::resolve_from(this.chunking_context).await? {
references.push(
ChunkListReferenceVc::new(context, chunk_group.entry(), chunk_group.chunks())
.into(),
);
}
Ok(AssetReferencesVc::cell(references))
} }
} }
...@@ -136,17 +147,15 @@ impl EcmascriptChunkItem for WithChunksChunkItem { ...@@ -136,17 +147,15 @@ impl EcmascriptChunkItem for WithChunksChunkItem {
let group = self.inner.chunk_group(); let group = self.inner.chunk_group();
let chunks = group.chunks().await?; let chunks = group.chunks().await?;
let server_root = inner.server_root.await?; let server_root = inner_chunking_context.output_root().await?;
let mut client_chunks = Vec::new(); let mut client_chunks = Vec::new();
let chunk_list_path = group.chunk_list_path().await?; for chunk_path in chunks
let chunk_list_path = if let Some(path) = server_root.get_path_to(&chunk_list_path) { .iter()
path .map(|chunk| chunk.ident().path())
} else { .try_join()
bail!("could not get path to chunk list"); .await?
}; {
for chunk_path in chunks.iter().map(|c| c.path()).try_join().await? {
if let Some(path) = server_root.get_path_to(&chunk_path) { if let Some(path) = server_root.get_path_to(&chunk_path) {
client_chunks.push(serde_json::Value::String(path.to_string())); client_chunks.push(serde_json::Value::String(path.to_string()));
} }
...@@ -156,21 +165,43 @@ impl EcmascriptChunkItem for WithChunksChunkItem { ...@@ -156,21 +165,43 @@ impl EcmascriptChunkItem for WithChunksChunkItem {
.as_chunk_item(inner_chunking_context) .as_chunk_item(inner_chunking_context)
.id() .id()
.await?; .await?;
Ok(EcmascriptChunkItemContent {
inner_code: formatdoc! { let mut code = RopeBuilder::default();
r#"
__turbopack_esm__({{ writedoc!(
default: () => {}, code,
chunks: () => chunks, r#"
chunkListPath: () => {}, __turbopack_esm__({{
}}); default: () => {},
const chunks = {:#}; chunks: () => chunks,
"#, "#,
StringifyJs(&module_id), StringifyJs(&module_id),
StringifyJs(&chunk_list_path), )?;
StringifyJs(&client_chunks),
if let Some(dev_chunking_context) =
DevChunkingContextVc::resolve_from(inner.chunking_context).await?
{
let chunk_list_path = dev_chunking_context
.chunk_list_path(group.entry().ident())
.await?;
if let Some(path) = server_root.get_path_to(&chunk_list_path) {
writeln!(code, " chunkListPath: () => {}", StringifyJs(&path))?;
} else {
bail!("could not get path to chunk list");
} }
.into(), }
writedoc!(
code,
r#"
}});
const chunks = {:#};
"#,
StringifyJs(&client_chunks),
)?;
Ok(EcmascriptChunkItemContent {
inner_code: code.build(),
..Default::default() ..Default::default()
} }
.cell()) .cell())
......
...@@ -6,8 +6,8 @@ use turbo_binding::{ ...@@ -6,8 +6,8 @@ use turbo_binding::{
core::{ core::{
asset::{Asset, AssetContentVc, AssetVc}, asset::{Asset, AssetContentVc, AssetVc},
chunk::{ chunk::{
availability_info::AvailabilityInfo, Chunk, ChunkGroupVc, ChunkItem, ChunkItemVc, availability_info::AvailabilityInfo, ChunkGroupVc, ChunkItem, ChunkItemVc, ChunkVc,
ChunkVc, ChunkableAsset, ChunkableAssetReference, ChunkableAssetReferenceVc, ChunkableAsset, ChunkableAssetReference, ChunkableAssetReferenceVc,
ChunkableAssetVc, ChunkingContext, ChunkingContextVc, ChunkingType, ChunkableAssetVc, ChunkingContext, ChunkingContextVc, ChunkingType,
ChunkingTypeOptionVc, ChunkingTypeOptionVc,
}, },
...@@ -140,7 +140,7 @@ impl EcmascriptChunkItem for WithClientChunksChunkItem { ...@@ -140,7 +140,7 @@ impl EcmascriptChunkItem for WithClientChunksChunkItem {
} }
} }
asset_paths.push(chunk.path().await?); asset_paths.push(chunk.ident().path().await?);
} }
let mut client_chunks = Vec::new(); let mut client_chunks = Vec::new();
......
...@@ -6,11 +6,11 @@ use turbo_binding::{ ...@@ -6,11 +6,11 @@ use turbo_binding::{
turbo::tasks_fs::{rope::RopeBuilder, File, FileContent, FileSystemPathVc}, turbo::tasks_fs::{rope::RopeBuilder, File, FileContent, FileSystemPathVc},
turbopack::{ turbopack::{
core::{ core::{
asset::{Asset, AssetContentVc, AssetVc}, asset::{Asset, AssetContentVc, AssetVc, AssetsVc},
chunk::{Chunk, ChunkGroupVc, ChunkReferenceVc, ChunkingContextVc, ChunksVc}, chunk::{ChunkGroupVc, ChunkingContextVc, EvaluatableAssetsVc},
context::{AssetContext, AssetContextVc}, context::{AssetContext, AssetContextVc},
ident::AssetIdentVc, ident::AssetIdentVc,
reference::AssetReferencesVc, reference::{AssetReferencesVc, SingleAssetReferenceVc},
reference_type::{EntryReferenceSubType, ReferenceType}, reference_type::{EntryReferenceSubType, ReferenceType},
virtual_asset::VirtualAssetVc, virtual_asset::VirtualAssetVc,
}, },
...@@ -81,7 +81,7 @@ impl PageLoaderAssetVc { ...@@ -81,7 +81,7 @@ impl PageLoaderAssetVc {
} }
#[turbo_tasks::function] #[turbo_tasks::function]
async fn get_page_chunks(self) -> Result<ChunksVc> { async fn get_page_chunks(self) -> Result<AssetsVc> {
let this = &*self.await?; let this = &*self.await?;
let loader_entry_asset = self.get_loader_entry_asset(); let loader_entry_asset = self.get_loader_entry_asset();
...@@ -100,13 +100,21 @@ impl PageLoaderAssetVc { ...@@ -100,13 +100,21 @@ impl PageLoaderAssetVc {
}), }),
); );
let chunk_group = let chunk_group = ChunkGroupVc::evaluated(
ChunkGroupVc::from_chunk(asset.as_evaluated_chunk(this.client_chunking_context, None)); this.client_chunking_context,
asset.into(),
EvaluatableAssetsVc::empty(),
);
Ok(chunk_group.chunks()) Ok(chunk_group.chunks())
} }
} }
#[turbo_tasks::function]
fn page_loader_chunk_reference_description() -> StringVc {
StringVc::cell("page loader chunk".to_string())
}
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl Asset for PageLoaderAsset { impl Asset for PageLoaderAsset {
#[turbo_tasks::function] #[turbo_tasks::function]
...@@ -131,7 +139,7 @@ impl Asset for PageLoaderAsset { ...@@ -131,7 +139,7 @@ impl Asset for PageLoaderAsset {
let server_root = server_root.clone(); let server_root = server_root.clone();
async move { async move {
Ok(server_root Ok(server_root
.get_path_to(&*chunk.path().await?) .get_path_to(&*chunk.ident().path().await?)
.map(|path| path.to_string())) .map(|path| path.to_string()))
} }
}) })
...@@ -156,7 +164,10 @@ impl Asset for PageLoaderAsset { ...@@ -156,7 +164,10 @@ impl Asset for PageLoaderAsset {
let mut references = Vec::with_capacity(chunks.len()); let mut references = Vec::with_capacity(chunks.len());
for chunk in chunks.iter() { for chunk in chunks.iter() {
references.push(ChunkReferenceVc::new(*chunk).into()); references.push(
SingleAssetReferenceVc::new(*chunk, page_loader_chunk_reference_description())
.into(),
);
} }
Ok(AssetReferencesVc::cell(references)) Ok(AssetReferencesVc::cell(references))
......
...@@ -9,7 +9,7 @@ use turbo_binding::{ ...@@ -9,7 +9,7 @@ use turbo_binding::{
turbopack::{ turbopack::{
core::{ core::{
asset::{AssetVc, AssetsVc}, asset::{AssetVc, AssetsVc},
chunk::ChunkingContextVc, chunk::{ChunkingContextVc, EvaluatableAssetVc, EvaluatableAssetsVc},
context::{AssetContext, AssetContextVc}, context::{AssetContext, AssetContextVc},
environment::{EnvironmentIntention, ServerAddrVc}, environment::{EnvironmentIntention, ServerAddrVc},
reference_type::{EntryReferenceSubType, ReferenceType}, reference_type::{EntryReferenceSubType, ReferenceType},
...@@ -373,6 +373,7 @@ async fn create_page_source_for_file( ...@@ -373,6 +373,7 @@ async fn create_page_source_for_file(
route_matcher.into(), route_matcher.into(),
pathname, pathname,
SsrEntry { SsrEntry {
runtime_entries,
context: server_context, context: server_context,
entry_asset: page_asset, entry_asset: page_asset,
ty: SsrType::AutoApi, ty: SsrType::AutoApi,
...@@ -383,7 +384,6 @@ async fn create_page_source_for_file( ...@@ -383,7 +384,6 @@ async fn create_page_source_for_file(
} }
.cell() .cell()
.into(), .into(),
runtime_entries,
) )
} else { } else {
let data_pathname = pathname_for_path(server_root, server_path, true, true); let data_pathname = pathname_for_path(server_root, server_path, true, true);
...@@ -391,6 +391,7 @@ async fn create_page_source_for_file( ...@@ -391,6 +391,7 @@ async fn create_page_source_for_file(
NextPrefixSuffixParamsMatcherVc::new(data_pathname, "_next/data/development/", ".json"); NextPrefixSuffixParamsMatcherVc::new(data_pathname, "_next/data/development/", ".json");
let ssr_entry = SsrEntry { let ssr_entry = SsrEntry {
runtime_entries,
context: server_context, context: server_context,
entry_asset: page_asset, entry_asset: page_asset,
ty: SsrType::Html, ty: SsrType::Html,
...@@ -403,6 +404,7 @@ async fn create_page_source_for_file( ...@@ -403,6 +404,7 @@ async fn create_page_source_for_file(
.into(); .into();
let ssr_data_entry = SsrEntry { let ssr_data_entry = SsrEntry {
runtime_entries,
context: server_data_context, context: server_data_context,
entry_asset: page_asset, entry_asset: page_asset,
ty: SsrType::Data, ty: SsrType::Data,
...@@ -423,7 +425,6 @@ async fn create_page_source_for_file( ...@@ -423,7 +425,6 @@ async fn create_page_source_for_file(
route_matcher.into(), route_matcher.into(),
pathname, pathname,
ssr_entry, ssr_entry,
runtime_entries,
fallback_page, fallback_page,
), ),
create_node_rendered_source( create_node_rendered_source(
...@@ -434,7 +435,6 @@ async fn create_page_source_for_file( ...@@ -434,7 +435,6 @@ async fn create_page_source_for_file(
data_route_matcher.into(), data_route_matcher.into(),
pathname, pathname,
ssr_data_entry, ssr_data_entry,
runtime_entries,
fallback_page, fallback_page,
), ),
create_page_loader( create_page_loader(
...@@ -519,6 +519,7 @@ async fn create_not_found_page_source( ...@@ -519,6 +519,7 @@ async fn create_not_found_page_source(
); );
let ssr_entry = SsrEntry { let ssr_entry = SsrEntry {
runtime_entries,
context: server_context, context: server_context,
entry_asset, entry_asset,
ty: SsrType::Html, ty: SsrType::Html,
...@@ -547,7 +548,6 @@ async fn create_not_found_page_source( ...@@ -547,7 +548,6 @@ async fn create_not_found_page_source(
route_matcher, route_matcher,
pathname, pathname,
ssr_entry, ssr_entry,
runtime_entries,
fallback_page, fallback_page,
), ),
page_loader, page_loader,
...@@ -662,6 +662,7 @@ enum SsrType { ...@@ -662,6 +662,7 @@ enum SsrType {
/// The node.js renderer for SSR of pages. /// The node.js renderer for SSR of pages.
#[turbo_tasks::value] #[turbo_tasks::value]
struct SsrEntry { struct SsrEntry {
runtime_entries: AssetsVc,
context: AssetContextVc, context: AssetContextVc,
entry_asset: AssetVc, entry_asset: AssetVc,
ty: SsrType, ty: SsrType,
...@@ -734,7 +735,13 @@ impl SsrEntryVc { ...@@ -734,7 +735,13 @@ impl SsrEntryVc {
}; };
Ok(NodeRenderingEntry { Ok(NodeRenderingEntry {
context: this.context, runtime_entries: EvaluatableAssetsVc::cell(
this.runtime_entries
.await?
.iter()
.map(|entry| EvaluatableAssetVc::from_asset(*entry, this.context))
.collect(),
),
module: EcmascriptModuleAssetVc::new_with_inner_assets( module: EcmascriptModuleAssetVc::new_with_inner_assets(
internal_asset, internal_asset,
this.context, this.context,
......
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use turbo_binding::{ use turbo_binding::{
turbo::tasks_fs::FileSystemPathVc, turbo::{
tasks::{TryJoinIterExt, Value},
tasks_fs::FileSystemPathVc,
},
turbopack::{ turbopack::{
core::{ core::{
chunk::{ chunk::{ChunkGroupVc, ChunkableAsset, ChunkableAssetVc},
availability_info::AvailabilityInfo, ChunkGroupVc, ChunkableAsset, ChunkableAssetVc,
},
compile_time_defines, compile_time_defines,
compile_time_info::{CompileTimeDefinesVc, CompileTimeInfo, CompileTimeInfoVc}, compile_time_info::{CompileTimeDefinesVc, CompileTimeInfo, CompileTimeInfoVc},
environment::{ environment::{
...@@ -23,7 +24,6 @@ use turbo_binding::{ ...@@ -23,7 +24,6 @@ use turbo_binding::{
turbopack::ecmascript::EcmascriptModuleAssetVc, turbopack::ecmascript::EcmascriptModuleAssetVc,
}, },
}; };
use turbo_tasks::{TryJoinIterExt, Value};
use crate::{ use crate::{
embed_js::next_js_file_path, embed_js::next_js_file_path,
...@@ -147,18 +147,16 @@ pub async fn create_web_entry_source( ...@@ -147,18 +147,16 @@ pub async fn create_web_entry_source(
.flatten() .flatten()
.map(|module| async move { .map(|module| async move {
if let Some(ecmascript) = EcmascriptModuleAssetVc::resolve_from(module).await? { if let Some(ecmascript) = EcmascriptModuleAssetVc::resolve_from(module).await? {
let chunk = ecmascript.as_evaluated_chunk(chunking_context, Some(runtime_entries)); let chunk_group =
let chunk_group = ChunkGroupVc::from_chunk(chunk); ChunkGroupVc::evaluated(chunking_context, ecmascript.into(), runtime_entries);
Ok(chunk_group) Ok(chunk_group)
} else if let Some(chunkable) = ChunkableAssetVc::resolve_from(module).await? { } else if let Some(chunkable) = ChunkableAssetVc::resolve_from(module).await? {
// TODO this is missing runtime code, so it's probably broken and we should also // TODO this is missing runtime code, so it's probably broken and we should also
// add an ecmascript chunk with the runtime code // add an ecmascript chunk with the runtime code
Ok(ChunkGroupVc::from_chunk(chunkable.as_chunk( Ok(ChunkGroupVc::from_chunk(
chunking_context, chunking_context,
Value::new(AvailabilityInfo::Root { chunkable.as_root_chunk(chunking_context),
current_availability_root: module, ))
}),
)))
} else { } else {
// TODO convert into a serve-able asset // TODO convert into a serve-able asset
Err(anyhow!( Err(anyhow!(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment