Skip to content
Draft
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
84 changes: 84 additions & 0 deletions crates/next-api/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,37 @@ impl Transition for RSCTransition {
}
}

// This is equivalent to `FullContextTransition::new(app_project.route_module_context())`
#[turbo_tasks::value]
struct RouteTransition {
app_project: ResolvedVc<AppProject>,
runtime: NextRuntime,
}
#[turbo_tasks::value_impl]
impl RouteTransition {
#[turbo_tasks::function]
pub fn new(app_project: ResolvedVc<AppProject>, runtime: NextRuntime) -> Vc<RouteTransition> {
RouteTransition {
app_project,
runtime,
}
.cell()
}
}
#[turbo_tasks::value_impl]
impl Transition for RouteTransition {
#[turbo_tasks::function]
fn process_context(
&self,
_module_asset_context: Vc<ModuleAssetContext>,
) -> Vc<ModuleAssetContext> {
match self.runtime {
NextRuntime::NodeJs => self.app_project.route_module_context(),
NextRuntime::Edge => self.app_project.edge_route_module_context(),
}
}
}

#[turbo_tasks::value_impl]
impl AppProject {
#[turbo_tasks::function]
Expand Down Expand Up @@ -413,6 +444,18 @@ impl AppProject {
rcstr!("next-server-component"),
ResolvedVc::upcast(NextServerComponentTransition::new().to_resolved().await?),
),
(
rcstr!("next-app-route"),
self.route_transition(NextRuntime::NodeJs)
.to_resolved()
.await?,
),
(
rcstr!("next-app-edge-route"),
self.route_transition(NextRuntime::Edge)
.to_resolved()
.await?,
),
// noops, but keep here to always have the transitions defined
(
rcstr!("next-rsc"),
Expand Down Expand Up @@ -626,6 +669,18 @@ impl AppProject {
rcstr!("next-dynamic-client"),
ResolvedVc::upcast(NextDynamicTransition::new_marker().to_resolved().await?),
),
(
rcstr!("next-app-route"),
self.route_transition(NextRuntime::NodeJs)
.to_resolved()
.await?,
),
(
rcstr!("next-app-edge-route"),
self.route_transition(NextRuntime::Edge)
.to_resolved()
.await?,
),
(
rcstr!("next-rsc"),
self.rsc_transition(NextRuntime::NodeJs)
Expand Down Expand Up @@ -728,6 +783,18 @@ impl AppProject {
rcstr!("next-shared"),
self.shared_transition().to_resolved().await?,
),
(
rcstr!("next-app-route"),
self.route_transition(NextRuntime::NodeJs)
.to_resolved()
.await?,
),
(
rcstr!("next-app-edge-route"),
self.route_transition(NextRuntime::Edge)
.to_resolved()
.await?,
),
(
rcstr!("next-rsc"),
self.rsc_transition(NextRuntime::NodeJs)
Expand Down Expand Up @@ -796,6 +863,11 @@ impl AppProject {
Vc::upcast(RSCTransition::new(self, runtime))
}

#[turbo_tasks::function]
fn route_transition(self: Vc<Self>, runtime: NextRuntime) -> Vc<Box<dyn Transition>> {
Vc::upcast(RouteTransition::new(self, runtime))
}

#[turbo_tasks::function]
async fn edge_ssr_module_context(self: Vc<Self>) -> Result<Vc<ModuleAssetContext>> {
let transitions = [
Expand All @@ -815,6 +887,18 @@ impl AppProject {
rcstr!("next-shared"),
self.edge_shared_transition().to_resolved().await?,
),
(
rcstr!("next-app-route"),
self.route_transition(NextRuntime::NodeJs)
.to_resolved()
.await?,
),
(
rcstr!("next-app-edge-route"),
self.route_transition(NextRuntime::Edge)
.to_resolved()
.await?,
),
(
rcstr!("next-rsc"),
self.rsc_transition(NextRuntime::NodeJs)
Expand Down
Loading