Skip to content
Draft
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
2 changes: 2 additions & 0 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions crates/next-api/src/dynamic_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use turbo_tasks::{
debug::ValueDebugFormat, trace::TraceRawVcs,
};
use turbopack_core::{
chunk::{ChunkableModule, ChunkingContext, availability_info::AvailabilityInfo},
chunk::{ChunkingContext, availability_info::AvailabilityInfo},
module::Module,
module_graph::{ModuleGraph, ModuleGraphLayer},
output::{OutputAssetsReference, OutputAssetsWithReferenced},
Expand All @@ -55,7 +55,7 @@ pub(crate) async fn collect_next_dynamic_chunks(
let dynamic_import_chunks = dynamic_import_entries
.iter()
.map(|(dynamic_entry, parent_client_reference)| async move {
let module = ResolvedVc::upcast::<Box<dyn ChunkableModule>>(*dynamic_entry);
let module = ResolvedVc::upcast::<Box<dyn Module>>(*dynamic_entry);

// This is the availability info for the parent chunk group, i.e. the client reference
// containing the next/dynamic imports
Expand Down
18 changes: 14 additions & 4 deletions crates/next-api/src/pages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,18 +657,28 @@ impl PageEndpoint {
Vc::upcast(this.pages_project.client_module_context()),
self.source(),
this.pathname.clone(),
);
)
.to_resolved()
.await?;
let is_chunkable = this
.pages_project
.project()
.client_chunking_context()
.chunking_configs()
.await?
.is_chunkable(page_loader)
.await;
if matches!(
*this.pages_project.project().next_mode().await?,
NextMode::Development
) && let Some(chunkable) = ResolvedVc::try_downcast(page_loader.to_resolved().await?)
) && is_chunkable
{
return Ok(Vc::upcast(HmrEntryModule::new(
AssetIdent::from_path(this.page.await?.base_path.clone()),
*chunkable,
*page_loader,
)));
}
Ok(page_loader)
Ok(*page_loader)
}

#[turbo_tasks::function]
Expand Down
8 changes: 3 additions & 5 deletions crates/next-api/src/server_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ use turbo_tasks::{
use turbo_tasks_fs::{self, File, FileContent, FileSystemPath, rope::RopeBuilder};
use turbopack_core::{
asset::AssetContent,
chunk::{
ChunkItem, ChunkItemExt, ChunkableModule, ChunkingContext, EvaluatableAsset, ModuleId,
},
chunk::{ChunkItem, ChunkItemExt, ChunkingContext, EvaluatableAsset, ModuleId},
context::AssetContext,
file_source::FileSource,
ident::AssetIdent,
Expand Down Expand Up @@ -78,7 +76,7 @@ pub(crate) async fn create_server_actions_manifest(
ResolvedVc::try_sidecast::<Box<dyn EvaluatableAsset>>(loader.to_resolved().await?)
.context("loader module must be evaluatable")?;

let chunk_item = loader.as_chunk_item(module_graph, chunking_context);
let chunk_item = ChunkItem::new(Vc::upcast(loader), module_graph, chunking_context);
let manifest = build_manifest(
node_root,
page_name,
Expand Down Expand Up @@ -158,7 +156,7 @@ async fn build_manifest(
page_name: RcStr,
runtime: NextRuntime,
actions: Vc<AllActions>,
chunk_item: Vc<Box<dyn ChunkItem>>,
chunk_item: Vc<ChunkItem>,
async_module_info: Vc<AsyncModulesInfo>,
) -> Result<ResolvedVc<Box<dyn OutputAsset>>> {
let manifest_path_prefix = &page_name;
Expand Down
3 changes: 1 addition & 2 deletions crates/next-api/src/webpack_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ where
{
let mut assets = vec![];
let mut chunks = vec![];
let mut chunk_items: FxIndexMap<Vc<Box<dyn ChunkItem>>, FxIndexSet<RcStr>> =
FxIndexMap::default();
let mut chunk_items: FxIndexMap<Vc<ChunkItem>, FxIndexSet<RcStr>> = FxIndexMap::default();

let entry_assets = entry_assets.into_iter().collect::<Vec<_>>();

Expand Down
29 changes: 7 additions & 22 deletions crates/next-core/src/hmr_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use turbo_tasks_fs::{FileSystem, VirtualFileSystem, rope::RopeBuilder};
use turbopack_core::{
asset::{Asset, AssetContent},
chunk::{
AsyncModuleInfo, ChunkItem, ChunkableModule, ChunkingContext, ChunkingType,
ChunkingTypeOption, EvaluatableAsset,
AsyncModuleInfo, ChunkItem, ChunkingContext, ChunkingType, ChunkingTypeOption,
EvaluatableAsset,
},
ident::AssetIdent,
module::{Module, ModuleSideEffects},
Expand All @@ -20,7 +20,7 @@ use turbopack_core::{
use turbopack_ecmascript::{
chunk::{
EcmascriptChunkItemContent, EcmascriptChunkItemOptions, EcmascriptChunkPlaceable,
EcmascriptExports, ecmascript_chunk_item,
EcmascriptExports,
},
runtime_functions::TURBOPACK_REQUIRE,
utils::StringifyJs,
Expand All @@ -41,16 +41,13 @@ async fn hmr_entry_point_base_ident() -> Result<Vc<AssetIdent>> {
#[turbo_tasks::value(shared)]
pub struct HmrEntryModule {
pub ident: ResolvedVc<AssetIdent>,
pub module: ResolvedVc<Box<dyn ChunkableModule>>,
pub module: ResolvedVc<Box<dyn Module>>,
}

#[turbo_tasks::value_impl]
impl HmrEntryModule {
#[turbo_tasks::function]
pub fn new(
ident: ResolvedVc<AssetIdent>,
module: ResolvedVc<Box<dyn ChunkableModule>>,
) -> Vc<Self> {
pub fn new(ident: ResolvedVc<AssetIdent>, module: ResolvedVc<Box<dyn Module>>) -> Vc<Self> {
Self { ident, module }.cell()
}
}
Expand All @@ -70,7 +67,7 @@ impl Module for HmrEntryModule {
#[turbo_tasks::function]
async fn references(&self) -> Result<Vc<ModuleReferences>> {
Ok(Vc::cell(vec![ResolvedVc::upcast(
HmrEntryModuleReference::new(Vc::upcast(*self.module))
HmrEntryModuleReference::new(*self.module)
.to_resolved()
.await?,
)]))
Expand All @@ -81,18 +78,6 @@ impl Module for HmrEntryModule {
}
}

#[turbo_tasks::value_impl]
impl ChunkableModule for HmrEntryModule {
#[turbo_tasks::function]
fn as_chunk_item(
self: ResolvedVc<Self>,
module_graph: ResolvedVc<ModuleGraph>,
chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
) -> Vc<Box<dyn ChunkItem>> {
ecmascript_chunk_item(ResolvedVc::upcast(self), module_graph, chunking_context)
}
}

#[turbo_tasks::value_impl]
impl Asset for HmrEntryModule {
#[turbo_tasks::function]
Expand All @@ -118,7 +103,7 @@ impl EcmascriptChunkPlaceable for HmrEntryModule {
) -> Result<Vc<EcmascriptChunkItemContent>> {
let this = self.await?;
let module = this.module;
let chunk_item = module.as_chunk_item(module_graph, chunking_context);
let chunk_item = ChunkItem::new(*module, module_graph, chunking_context);
let id = chunking_context
.chunk_item_id_strategy()
.await?
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,26 @@
use std::{io::Write, iter::once};

use anyhow::{Context, Result, bail};
use anyhow::{Result, bail};
use indoc::writedoc;
use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{IntoTraitRef, ResolvedVc, ValueToString, Vc};
use turbo_tasks_fs::{File, FileContent};
use turbopack_core::{
asset::AssetContent,
chunk::{
AsyncModuleInfo, ChunkGroupType, ChunkItem, ChunkType, ChunkableModule, ChunkingContext,
ChunkingType, ChunkingTypeOption,
},
chunk::{AsyncModuleInfo, ChunkGroupType, ChunkingContext, ChunkingType, ChunkingTypeOption},
code_builder::CodeBuilder,
context::AssetContext,
ident::AssetIdent,
module::{Module, ModuleSideEffects},
module_graph::{ModuleGraph, binding_usage_info::ModuleExportUsageInfo},
output::OutputAssetsReference,
reference::{ModuleReference, ModuleReferences},
reference_type::ReferenceType,
resolve::ModuleResolveResult,
source::OptionSource,
virtual_source::VirtualSource,
};
use turbopack_ecmascript::{
chunk::{
EcmascriptChunkItem, EcmascriptChunkItemContent, EcmascriptChunkPlaceable,
EcmascriptChunkType, EcmascriptExports,
},
chunk::{EcmascriptChunkItemContent, EcmascriptChunkPlaceable, EcmascriptExports},
runtime_functions::TURBOPACK_EXPORT_NAMESPACE,
utils::StringifyJs,
};
Expand Down Expand Up @@ -249,32 +242,6 @@ impl Module for EcmascriptClientReferenceModule {
}
}

#[turbo_tasks::value_impl]
impl ChunkableModule for EcmascriptClientReferenceModule {
#[turbo_tasks::function]
async fn as_chunk_item(
self: ResolvedVc<Self>,
module_graph: Vc<ModuleGraph>,
chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
) -> Result<Vc<Box<dyn ChunkItem>>> {
let item = self
.proxy_module()
.as_chunk_item(module_graph, *chunking_context);
let ecmascript_item =
ResolvedVc::try_downcast::<Box<dyn EcmascriptChunkItem>>(item.to_resolved().await?)
.context("EcmascriptModuleAsset must implement EcmascriptChunkItem")?;

Ok(Vc::upcast(
EcmascriptClientReferenceProxyChunkItem {
inner_module: self,
inner_chunk_item: ecmascript_item,
chunking_context,
}
.cell(),
))
}
}

#[turbo_tasks::value_impl]
impl EcmascriptChunkPlaceable for EcmascriptClientReferenceModule {
#[turbo_tasks::function]
Expand All @@ -285,67 +252,17 @@ impl EcmascriptChunkPlaceable for EcmascriptClientReferenceModule {
#[turbo_tasks::function]
fn chunk_item_content(
self: Vc<Self>,
_chunking_context: Vc<Box<dyn ChunkingContext>>,
_module_graph: Vc<ModuleGraph>,
_async_module_info: Option<Vc<AsyncModuleInfo>>,
_estimated: bool,
) -> Result<Vc<EcmascriptChunkItemContent>> {
bail!("Attempted to get chunk_item_content for EcmascriptClientReferenceModule")
}
}

/// This wrapper only exists to overwrite the `asset_ident` method of the
/// wrapped [`Vc<Box<dyn EcmascriptChunkItem>>`]. Otherwise, the asset ident of
/// the chunk item would not be the same as the asset ident of the
/// [`Vc<EcmascriptClientReferenceModule>`].
#[turbo_tasks::value]
struct EcmascriptClientReferenceProxyChunkItem {
inner_module: ResolvedVc<EcmascriptClientReferenceModule>,
inner_chunk_item: ResolvedVc<Box<dyn EcmascriptChunkItem>>,
chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
}

#[turbo_tasks::value_impl]
impl OutputAssetsReference for EcmascriptClientReferenceProxyChunkItem {}

#[turbo_tasks::value_impl]
impl ChunkItem for EcmascriptClientReferenceProxyChunkItem {
#[turbo_tasks::function]
fn asset_ident(&self) -> Vc<AssetIdent> {
self.inner_module.ident()
}

#[turbo_tasks::function]
fn chunking_context(&self) -> Vc<Box<dyn ChunkingContext>> {
*self.chunking_context
}

#[turbo_tasks::function]
fn ty(&self) -> Vc<Box<dyn ChunkType>> {
Vc::upcast(Vc::<EcmascriptChunkType>::default())
}

#[turbo_tasks::function]
fn module(&self) -> Vc<Box<dyn Module>> {
Vc::upcast(*self.inner_module)
}
}

#[turbo_tasks::value_impl]
impl EcmascriptChunkItem for EcmascriptClientReferenceProxyChunkItem {
#[turbo_tasks::function]
fn content(&self) -> Vc<EcmascriptChunkItemContent> {
self.inner_chunk_item.content()
}

#[turbo_tasks::function]
fn content_with_async_module_info(
&self,
chunking_context: Vc<Box<dyn ChunkingContext>>,
module_graph: Vc<ModuleGraph>,
async_module_info: Option<Vc<AsyncModuleInfo>>,
estimated: bool,
) -> Vc<EcmascriptChunkItemContent> {
self.inner_chunk_item
.content_with_async_module_info(async_module_info, estimated)
self.proxy_module().chunk_item_content(
chunking_context,
module_graph,
async_module_info,
estimated,
)
}
}

Expand Down
19 changes: 2 additions & 17 deletions crates/next-core/src/next_dynamic/dynamic_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use indoc::formatdoc;
use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{ResolvedVc, Vc};
use turbopack_core::{
chunk::{AsyncModuleInfo, ChunkableModule, ChunkingContext, ModuleChunkItemIdExt},
chunk::{AsyncModuleInfo, ChunkingContext, ModuleChunkItemIdExt},
ident::AssetIdent,
module::{Module, ModuleSideEffects},
module_graph::ModuleGraph,
Expand All @@ -14,10 +14,7 @@ use turbopack_core::{
source::OptionSource,
};
use turbopack_ecmascript::{
chunk::{
EcmascriptChunkItemContent, EcmascriptChunkPlaceable, EcmascriptExports,
ecmascript_chunk_item,
},
chunk::{EcmascriptChunkItemContent, EcmascriptChunkPlaceable, EcmascriptExports},
references::esm::{EsmExport, EsmExports},
runtime_functions::{TURBOPACK_EXPORT_NAMESPACE, TURBOPACK_IMPORT},
utils::StringifyJs,
Expand Down Expand Up @@ -75,18 +72,6 @@ impl Module for NextDynamicEntryModule {
}
}

#[turbo_tasks::value_impl]
impl ChunkableModule for NextDynamicEntryModule {
#[turbo_tasks::function]
fn as_chunk_item(
self: ResolvedVc<Self>,
module_graph: ResolvedVc<ModuleGraph>,
chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
) -> Vc<Box<dyn turbopack_core::chunk::ChunkItem>> {
ecmascript_chunk_item(ResolvedVc::upcast(self), module_graph, chunking_context)
}
}

#[turbo_tasks::value_impl]
impl EcmascriptChunkPlaceable for NextDynamicEntryModule {
#[turbo_tasks::function]
Expand Down
Loading
Loading