Skip to content

Commit

Permalink
refactor(turbopack/next-core): Remove uses of generic vc collections
Browse files Browse the repository at this point in the history
  • Loading branch information
bgw committed Oct 7, 2024
1 parent 5b27b7d commit e79bded
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
8 changes: 4 additions & 4 deletions crates/next-api/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use next_core::{
app_segment_config::NextSegmentConfig,
app_structure::{
get_entrypoints, AppPageLoaderTree, Entrypoint as AppEntrypoint,
Entrypoints as AppEntrypoints, MetadataItem,
Entrypoints as AppEntrypoints, FileSystemPathVec, MetadataItem,
},
get_edge_resolve_options_context, get_next_package,
next_app::{
Expand Down Expand Up @@ -705,7 +705,7 @@ enum AppEndpointType {
},
Route {
path: Vc<FileSystemPath>,
root_layouts: Vc<Vec<Vc<FileSystemPath>>>,
root_layouts: Vc<FileSystemPathVec>,
},
Metadata {
metadata: MetadataItem,
Expand Down Expand Up @@ -737,7 +737,7 @@ impl AppEndpoint {
async fn app_route_entry(
&self,
path: Vc<FileSystemPath>,
root_layouts: Vc<Vec<Vc<FileSystemPath>>>,
root_layouts: Vc<FileSystemPathVec>,
next_config: Vc<NextConfig>,
) -> Result<Vc<AppEntry>> {
let root_layouts = root_layouts.await?;
Expand All @@ -747,7 +747,7 @@ impl AppEndpoint {
let mut config = NextSegmentConfig::default();

for layout in root_layouts.iter().rev() {
let source = Vc::upcast(FileSource::new(*layout));
let source = Vc::upcast(FileSource::new(**layout));
let layout_config = parse_segment_config_from_source(source);
config.apply_parent_config(&*layout_config.await?);
}
Expand Down
34 changes: 24 additions & 10 deletions crates/next-core/src/app_structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use serde::{Deserialize, Serialize};
use tracing::Instrument;
use turbo_tasks::{
debug::ValueDebugFormat, trace::TraceRawVcs, RcStr, ResolvedVc, TaskInput, TryJoinIterExt,
ValueToString, Vc,
ValueDefault, ValueToString, Vc,
};
use turbo_tasks_fs::{DirectoryContent, DirectoryEntry, FileSystemEntryType, FileSystemPath};
use turbopack_core::issue::{
Expand Down Expand Up @@ -467,6 +467,17 @@ impl AppPageLoaderTree {
}
}

#[turbo_tasks::value(transparent)]
pub struct FileSystemPathVec(Vec<ResolvedVc<FileSystemPath>>);

#[turbo_tasks::value_impl]
impl ValueDefault for FileSystemPathVec {
#[turbo_tasks::function]
fn value_default() -> Vc<Self> {
Vc::cell(Vec::new())
}
}

#[derive(
Clone,
PartialEq,
Expand All @@ -487,7 +498,7 @@ pub enum Entrypoint {
AppRoute {
page: AppPage,
path: ResolvedVc<FileSystemPath>,
root_layouts: ResolvedVc<Vec<Vc<FileSystemPath>>>,
root_layouts: ResolvedVc<FileSystemPathVec>,
},
AppMetadata {
page: AppPage,
Expand Down Expand Up @@ -615,7 +626,7 @@ fn add_app_route(
result: &mut IndexMap<AppPath, Entrypoint>,
page: AppPage,
path: ResolvedVc<FileSystemPath>,
root_layouts: ResolvedVc<Vec<Vc<FileSystemPath>>>,
root_layouts: ResolvedVc<FileSystemPathVec>,
) {
let e = match result.entry(page.clone().into()) {
Entry::Occupied(e) => e,
Expand Down Expand Up @@ -709,7 +720,7 @@ fn directory_tree_to_entrypoints(
app_dir: Vc<FileSystemPath>,
directory_tree: Vc<DirectoryTree>,
global_metadata: Vc<GlobalMetadata>,
root_layouts: Vc<Vec<Vc<FileSystemPath>>>,
root_layouts: Vc<FileSystemPathVec>,
) -> Vc<Entrypoints> {
directory_tree_to_entrypoints_internal(
app_dir,
Expand Down Expand Up @@ -792,6 +803,9 @@ fn check_duplicate(
}
}

#[turbo_tasks::value(transparent)]
struct AppPageLoaderTreeOption(Option<ResolvedVc<AppPageLoaderTree>>);

/// creates the loader tree for a specific route (pathname / [AppPath])
#[turbo_tasks::function]
async fn directory_tree_to_loader_tree(
Expand All @@ -802,7 +816,7 @@ async fn directory_tree_to_loader_tree(
app_page: AppPage,
// the page this loader tree is constructed for
for_app_path: AppPath,
) -> Result<Vc<Option<Vc<AppPageLoaderTree>>>> {
) -> Result<Vc<AppPageLoaderTreeOption>> {
let plain_tree = &*directory_tree.into_plain().await?;

let tree = directory_tree_to_loader_tree_internal(
Expand All @@ -814,7 +828,7 @@ async fn directory_tree_to_loader_tree(
for_app_path,
)?;

Ok(Vc::cell(tree.map(|tree| tree.cell())))
Ok(Vc::cell(tree.map(AppPageLoaderTree::resolved_cell)))
}

fn directory_tree_to_loader_tree_internal(
Expand Down Expand Up @@ -1044,7 +1058,7 @@ async fn directory_tree_to_entrypoints_internal(
directory_name: RcStr,
directory_tree: Vc<DirectoryTree>,
app_page: AppPage,
root_layouts: ResolvedVc<Vec<Vc<FileSystemPath>>>,
root_layouts: ResolvedVc<FileSystemPathVec>,
) -> Result<Vc<Entrypoints>> {
let span = tracing::info_span!("build layout trees", name = display(&app_page));
directory_tree_to_entrypoints_internal_untraced(
Expand All @@ -1065,7 +1079,7 @@ async fn directory_tree_to_entrypoints_internal_untraced(
directory_name: RcStr,
directory_tree: Vc<DirectoryTree>,
app_page: AppPage,
root_layouts: ResolvedVc<Vec<Vc<FileSystemPath>>>,
root_layouts: ResolvedVc<FileSystemPathVec>,
) -> Result<Vc<Entrypoints>> {
let mut result = IndexMap::new();

Expand All @@ -1078,8 +1092,8 @@ async fn directory_tree_to_entrypoints_internal_untraced(
// segment config. https://nextjs.org/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes#segment-runtime-option
// Pass down layouts from each tree to apply segment config when adding route.
let root_layouts = if let Some(layout) = modules.layout {
let mut layouts = (*root_layouts.await?).clone();
layouts.push(layout);
let mut layouts = root_layouts.await?.clone_value();
layouts.push(layout.to_resolved().await?);
ResolvedVc::cell(layouts)
} else {
root_layouts
Expand Down

0 comments on commit e79bded

Please sign in to comment.