Skip to content

Commit

Permalink
Fix next server component modules in graph traversal (#69157)
Browse files Browse the repository at this point in the history
Next entry modules with the "client modules" or "client modules ssr" modifiers were not being reached by graph traversal. Now they are.
  • Loading branch information
LichuAcu committed Aug 27, 2024
1 parent af6ff37 commit 69c2d0c
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 4 deletions.
4 changes: 2 additions & 2 deletions crates/next-core/src/next_app/app_client_references_chunks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ use crate::{
};

#[turbo_tasks::function]
fn client_modules_modifier() -> Vc<RcStr> {
pub fn client_modules_modifier() -> Vc<RcStr> {
Vc::cell("client modules".into())
}

#[turbo_tasks::function]
fn client_modules_ssr_modifier() -> Vc<RcStr> {
pub fn client_modules_ssr_modifier() -> Vc<RcStr> {
Vc::cell("client modules ssr".into())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,22 @@ use turbopack_core::{
asset::{Asset, AssetContent},
chunk::{ChunkItem, ChunkItemExt, ChunkType, ChunkableModule, ChunkingContext},
ident::AssetIdent,
module::Module,
module::{Module, Modules},
reference::ModuleReferences,
};
use turbopack_ecmascript::{
chunk::{
EcmascriptChunkItem, EcmascriptChunkItemContent, EcmascriptChunkPlaceable,
EcmascriptChunkType, EcmascriptExports,
},
references::esm::EsmExports,
references::{esm::EsmExports, external_module::IncludeIdentModule},
utils::StringifyJs,
};

use super::server_component_reference::NextServerComponentModuleReference;
use crate::next_app::app_client_references_chunks::{
client_modules_modifier, client_modules_ssr_modifier,
};

#[turbo_tasks::function]
fn modifier() -> Vc<RcStr> {
Expand Down Expand Up @@ -57,6 +60,18 @@ impl Module for NextServerComponentModule {
Vc::upcast(self.module),
))])
}

#[turbo_tasks::function]
fn additional_layers_modules(self: Vc<Self>) -> Vc<Modules> {
let base_ident = self.ident();
let ssr_entry_module = Vc::upcast(IncludeIdentModule::new(
base_ident.with_modifier(client_modules_ssr_modifier()),
));
let client_entry_module = Vc::upcast(IncludeIdentModule::new(
base_ident.with_modifier(client_modules_modifier()),
));
Vc::cell(vec![ssr_entry_module, client_entry_module])
}
}

#[turbo_tasks::value_impl]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,34 @@ impl EcmascriptChunkItem for CachedExternalModuleChunkItem {
))
}
}

/// A module that only has an ident and no content. This is used
/// to include a module's ident in the module graph before the module
/// itself is resolved, as is the case with NextServerComponentModule's
/// "client modules" and "client modules ssr".
#[turbo_tasks::value]
pub struct IncludeIdentModule {
ident: Vc<AssetIdent>,
}

#[turbo_tasks::value_impl]
impl IncludeIdentModule {
#[turbo_tasks::function]
pub fn new(ident: Vc<AssetIdent>) -> Vc<Self> {
Self { ident }.cell()
}
}

impl Asset for IncludeIdentModule {
fn content(self: Vc<Self>) -> Vc<AssetContent> {
todo!("IncludeIdentModule doesn't implement content()")
}
}

#[turbo_tasks::value_impl]
impl Module for IncludeIdentModule {
#[turbo_tasks::function]
fn ident(&self) -> Vc<AssetIdent> {
self.ident
}
}

0 comments on commit 69c2d0c

Please sign in to comment.