-
Notifications
You must be signed in to change notification settings - Fork 27.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Turbopack: migrate client references to single-graph-traversal #73322
Merged
mischnic
merged 10 commits into
canary
from
mischnic/single-traversal-client-references
Dec 11, 2024
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c475377
migrate client references to single-traversal
mischnic 8fc4e0e
Add hack to detect server components in edge properly
mischnic 698f93c
Update for SingleModuleGraphNode
mischnic a42c148
NextServerUtilityTransition to remove hack
mischnic d550764
Use `iter_nodes` instead
mischnic 961ff87
Add another NextServerUtilityTransition
mischnic 2cbca3b
Fixup
mischnic a8e1f45
Fix pages router
mischnic 40ceec8
Collect client references in correct order
mischnic 3f5ca85
Address review suggestions
mischnic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
use std::collections::HashMap; | ||
|
||
use anyhow::Result; | ||
use next_core::{ | ||
self, next_client_reference::EcmascriptClientReferenceModule, | ||
next_server_component::server_component_module::NextServerComponentModule, | ||
}; | ||
use serde::{Deserialize, Serialize}; | ||
use turbo_tasks::{ | ||
debug::ValueDebugFormat, trace::TraceRawVcs, ResolvedVc, TryFlatJoinIterExt, Vc, | ||
}; | ||
use turbopack::css::CssModuleAsset; | ||
use turbopack_core::module::Module; | ||
|
||
use crate::module_graph::SingleModuleGraph; | ||
|
||
#[derive(Clone, Serialize, Deserialize, Eq, PartialEq, TraceRawVcs, ValueDebugFormat)] | ||
pub enum ClientReferenceMapType { | ||
EcmascriptClientReference { | ||
module: ResolvedVc<EcmascriptClientReferenceModule>, | ||
ssr_module: ResolvedVc<Box<dyn Module>>, | ||
}, | ||
CssClientReference(ResolvedVc<CssModuleAsset>), | ||
ServerComponent(ResolvedVc<NextServerComponentModule>), | ||
} | ||
|
||
#[turbo_tasks::value(transparent)] | ||
pub struct ClientReferencesSet(HashMap<ResolvedVc<Box<dyn Module>>, ClientReferenceMapType>); | ||
|
||
#[turbo_tasks::function] | ||
pub async fn map_client_references( | ||
graph: Vc<SingleModuleGraph>, | ||
) -> Result<Vc<ClientReferencesSet>> { | ||
let actions = graph | ||
.await? | ||
.iter_nodes() | ||
.map(|node| async move { | ||
let module = node.module; | ||
if let Some(client_reference_module) = | ||
ResolvedVc::try_downcast_type::<EcmascriptClientReferenceModule>(module).await? | ||
{ | ||
Ok(Some(( | ||
module, | ||
ClientReferenceMapType::EcmascriptClientReference { | ||
module: client_reference_module, | ||
ssr_module: ResolvedVc::upcast(client_reference_module.await?.ssr_module), | ||
}, | ||
))) | ||
} else if let Some(css_client_reference_asset) = | ||
ResolvedVc::try_downcast_type::<CssModuleAsset>(module).await? | ||
{ | ||
Ok(Some(( | ||
module, | ||
ClientReferenceMapType::CssClientReference(css_client_reference_asset), | ||
))) | ||
} else if let Some(server_component) = | ||
ResolvedVc::try_downcast_type::<NextServerComponentModule>(module).await? | ||
{ | ||
Ok(Some(( | ||
module, | ||
ClientReferenceMapType::ServerComponent(server_component), | ||
))) | ||
} else { | ||
Ok(None) | ||
} | ||
}) | ||
.try_flat_join() | ||
.await?; | ||
Ok(Vc::cell(actions.into_iter().collect())) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To improve incremental builds this could take a
Vc<ModulesSet>
as argument instead of the full graph. Since aModulesSet
isPartialEq
we could cache that step for some changes of the graph.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll try that in a future PR.
(Effectively this set would be the
nodes: Vec<Node<N, Ix>>
that is currently stored in the petgraph.)