Skip to content

Commit

Permalink
refactor(turbopack/next-core): Use ResolvedVc in VisitClientReference…
Browse files Browse the repository at this point in the history
…NodeState
  • Loading branch information
bgw committed Jan 11, 2025
1 parent 28116ac commit 9bcf753
Showing 1 changed file with 31 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl Default for ClientReferenceGraphResult {
}
}

#[turbo_tasks::value(shared, local)]
#[turbo_tasks::value(shared)]
pub struct VisitedClientReferenceGraphNodes(HashSet<VisitClientReferenceNode>);

#[turbo_tasks::value_impl]
Expand Down Expand Up @@ -169,11 +169,11 @@ pub async fn client_reference_graph(
.await?
{
VisitClientReferenceNodeState::InServerComponent {
server_component: *server_component,
server_component,
}
} else {
VisitClientReferenceNodeState::Entry {
entry_path: module.ident().path().resolve().await?,
entry_path: module.ident().path().to_resolved().await?,
}
},
ty: VisitClientReferenceNodeType::Internal(
Expand Down Expand Up @@ -244,7 +244,7 @@ pub struct ServerEntries {

#[turbo_tasks::function]
pub async fn find_server_entries(entry: ResolvedVc<Box<dyn Module>>) -> Result<Vc<ServerEntries>> {
let entry_path = entry.ident().path().resolve().await?;
let entry_path = entry.ident().path().to_resolved().await?;
let graph = AdjacencyMap::new()
.skip_duplicates()
.visit(
Expand Down Expand Up @@ -288,27 +288,46 @@ struct VisitClientReference {
}

#[derive(
Clone, Eq, PartialEq, Hash, Serialize, Deserialize, Debug, ValueDebugFormat, TraceRawVcs,
Clone,
Eq,
PartialEq,
Hash,
Serialize,
Deserialize,
Debug,
ValueDebugFormat,
TraceRawVcs,
NonLocalValue,
)]
struct VisitClientReferenceNode {
state: VisitClientReferenceNodeState,
ty: VisitClientReferenceNodeType,
}

#[derive(
Clone, Copy, Eq, PartialEq, Hash, Serialize, Deserialize, Debug, ValueDebugFormat, TraceRawVcs,
Clone,
Copy,
Eq,
PartialEq,
Hash,
Serialize,
Deserialize,
Debug,
ValueDebugFormat,
TraceRawVcs,
NonLocalValue,
)]
enum VisitClientReferenceNodeState {
Entry {
entry_path: Vc<FileSystemPath>,
entry_path: ResolvedVc<FileSystemPath>,
},
InServerComponent {
server_component: Vc<NextServerComponentModule>,
server_component: ResolvedVc<NextServerComponentModule>,
},
InServerUtil,
}
impl VisitClientReferenceNodeState {
fn server_component(&self) -> Option<Vc<NextServerComponentModule>> {
fn server_component(&self) -> Option<ResolvedVc<NextServerComponentModule>> {
match self {
VisitClientReferenceNodeState::Entry { .. } => None,
VisitClientReferenceNodeState::InServerComponent { server_component } => {
Expand Down Expand Up @@ -389,12 +408,7 @@ impl Visit<VisitClientReferenceNode> for VisitClientReference {
state: node.state,
ty: VisitClientReferenceNodeType::ClientReference(
ClientReference {
server_component: match node.state.server_component() {
Some(server_component) => {
Some(server_component.to_resolved().await?)
}
None => None,
},
server_component: node.state.server_component(),
ty: ClientReferenceType::EcmascriptClientReference {
parent_module,
module: client_reference_module,
Expand All @@ -412,12 +426,7 @@ impl Visit<VisitClientReferenceNode> for VisitClientReference {
state: node.state,
ty: VisitClientReferenceNodeType::ClientReference(
ClientReference {
server_component: match node.state.server_component() {
Some(server_component) => {
Some(server_component.to_resolved().await?)
}
None => None,
},
server_component: node.state.server_component(),
ty: ClientReferenceType::CssClientReference(
css_client_reference_asset,
),
Expand All @@ -432,7 +441,7 @@ impl Visit<VisitClientReferenceNode> for VisitClientReference {
{
return Ok(VisitClientReferenceNode {
state: VisitClientReferenceNodeState::InServerComponent {
server_component: *server_component_asset,
server_component: server_component_asset,
},
ty: VisitClientReferenceNodeType::ServerComponentEntry(
server_component_asset,
Expand Down

0 comments on commit 9bcf753

Please sign in to comment.