Skip to content

Commit c2d19b8

Browse files
committed
Use FullContextTransition-s
1 parent af58741 commit c2d19b8

File tree

4 files changed

+94
-28
lines changed

4 files changed

+94
-28
lines changed

Diff for: crates/next-api/src/app.rs

+27-7
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ use turbo_tasks_fs::{File, FileContent, FileSystemPath};
4747
use turbopack::{
4848
module_options::{transition_rule::TransitionRule, ModuleOptionsContext, RuleCondition},
4949
resolve_options_context::ResolveOptionsContext,
50-
transition::{ContextTransition, FullContextTransition, Transition, TransitionOptions},
50+
transition::{FullContextTransition, Transition, TransitionOptions},
5151
ModuleAssetContext,
5252
};
5353
use turbopack_core::{
@@ -663,13 +663,22 @@ impl AppProject {
663663
}
664664

665665
#[turbo_tasks::function]
666-
fn shared_transition(self: Vc<Self>) -> Vc<ContextTransition> {
667-
ContextTransition::new(
666+
async fn shared_module_context(self: Vc<Self>) -> Result<Vc<ModuleAssetContext>> {
667+
Ok(ModuleAssetContext::new(
668+
TransitionOptions {
669+
..Default::default()
670+
}
671+
.cell(),
668672
self.project().server_compile_time_info(),
669673
self.ssr_module_options_context(),
670674
self.ssr_resolve_options_context(),
671675
Vc::cell("app-shared".into()),
672-
)
676+
))
677+
}
678+
679+
#[turbo_tasks::function]
680+
fn shared_transition(self: Vc<Self>) -> Vc<Box<dyn Transition>> {
681+
Vc::upcast(FullContextTransition::new(self.shared_module_context()))
673682
}
674683

675684
#[turbo_tasks::function]
@@ -714,13 +723,24 @@ impl AppProject {
714723
}
715724

716725
#[turbo_tasks::function]
717-
fn edge_shared_transition(self: Vc<Self>) -> Vc<ContextTransition> {
718-
ContextTransition::new(
726+
async fn edge_shared_module_context(self: Vc<Self>) -> Result<Vc<ModuleAssetContext>> {
727+
Ok(ModuleAssetContext::new(
728+
TransitionOptions {
729+
..Default::default()
730+
}
731+
.cell(),
719732
self.project().edge_compile_time_info(),
720733
self.edge_ssr_module_options_context(),
721734
self.edge_ssr_resolve_options_context(),
722735
Vc::cell("app-edge-shared".into()),
723-
)
736+
))
737+
}
738+
739+
#[turbo_tasks::function]
740+
fn edge_shared_transition(self: Vc<Self>) -> Vc<Box<dyn Transition>> {
741+
Vc::upcast(FullContextTransition::new(
742+
self.edge_shared_module_context(),
743+
))
724744
}
725745

726746
#[turbo_tasks::function]

Diff for: crates/next-api/src/pages.rs

+42-19
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use turbo_tasks_fs::{
3939
use turbopack::{
4040
module_options::ModuleOptionsContext,
4141
resolve_options_context::ResolveOptionsContext,
42-
transition::{ContextTransition, TransitionOptions},
42+
transition::{FullContextTransition, Transition, TransitionOptions},
4343
ModuleAssetContext,
4444
};
4545
use turbopack_core::{
@@ -290,7 +290,27 @@ impl PagesProject {
290290
}
291291

292292
#[turbo_tasks::function]
293-
async fn transitions(self: Vc<Self>) -> Result<Vc<TransitionOptions>> {
293+
async fn client_transitions(self: Vc<Self>) -> Result<Vc<TransitionOptions>> {
294+
Ok(TransitionOptions {
295+
named_transitions: [
296+
(
297+
"next-dynamic".into(),
298+
ResolvedVc::upcast(NextDynamicTransition::new_marker().to_resolved().await?),
299+
),
300+
(
301+
"next-dynamic-client".into(),
302+
ResolvedVc::upcast(NextDynamicTransition::new_marker().to_resolved().await?),
303+
),
304+
]
305+
.into_iter()
306+
.collect(),
307+
..Default::default()
308+
}
309+
.cell())
310+
}
311+
312+
#[turbo_tasks::function]
313+
async fn server_transitions(self: Vc<Self>) -> Result<Vc<TransitionOptions>> {
294314
Ok(TransitionOptions {
295315
named_transitions: [
296316
(
@@ -314,13 +334,16 @@ impl PagesProject {
314334
}
315335

316336
#[turbo_tasks::function]
317-
fn client_transition(self: Vc<Self>) -> Vc<ContextTransition> {
318-
ContextTransition::new(
319-
self.project().client_compile_time_info(),
320-
self.client_module_options_context(),
321-
self.client_resolve_options_context(),
322-
client_layer(),
323-
)
337+
fn client_transition(self: Vc<Self>) -> Vc<Box<dyn Transition>> {
338+
Vc::upcast(FullContextTransition::new(self.client_module_context()))
339+
340+
// Vc::upcast(ContextTransition::new(
341+
// self.project().client_compile_time_info(),
342+
// self.client_module_options_context(),
343+
// self.client_resolve_options_context(),
344+
// TransitionOptions::value_default(),
345+
// client_layer(),
346+
// ))
324347
}
325348

326349
#[turbo_tasks::function]
@@ -353,20 +376,20 @@ impl PagesProject {
353376
}
354377

355378
#[turbo_tasks::function]
356-
pub(super) fn client_module_context(self: Vc<Self>) -> Vc<Box<dyn AssetContext>> {
357-
Vc::upcast(ModuleAssetContext::new(
358-
self.transitions(),
379+
pub(super) fn client_module_context(self: Vc<Self>) -> Vc<ModuleAssetContext> {
380+
ModuleAssetContext::new(
381+
self.client_transitions(),
359382
self.project().client_compile_time_info(),
360383
self.client_module_options_context(),
361384
self.client_resolve_options_context(),
362385
client_layer(),
363-
))
386+
)
364387
}
365388

366389
#[turbo_tasks::function]
367390
pub(super) fn ssr_module_context(self: Vc<Self>) -> Vc<ModuleAssetContext> {
368391
ModuleAssetContext::new(
369-
self.transitions(),
392+
self.server_transitions(),
370393
self.project().server_compile_time_info(),
371394
self.ssr_module_options_context(),
372395
self.ssr_resolve_options_context(),
@@ -379,7 +402,7 @@ impl PagesProject {
379402
#[turbo_tasks::function]
380403
pub(super) fn api_module_context(self: Vc<Self>) -> Vc<ModuleAssetContext> {
381404
ModuleAssetContext::new(
382-
self.transitions(),
405+
self.server_transitions(),
383406
self.project().server_compile_time_info(),
384407
self.api_module_options_context(),
385408
self.ssr_resolve_options_context(),
@@ -390,7 +413,7 @@ impl PagesProject {
390413
#[turbo_tasks::function]
391414
pub(super) fn ssr_data_module_context(self: Vc<Self>) -> Vc<ModuleAssetContext> {
392415
ModuleAssetContext::new(
393-
self.transitions(),
416+
self.server_transitions(),
394417
self.project().server_compile_time_info(),
395418
self.ssr_data_module_options_context(),
396419
self.ssr_resolve_options_context(),
@@ -566,7 +589,7 @@ impl PagesProject {
566589
self.project().next_config(),
567590
self.project().execution_context(),
568591
);
569-
Ok(client_runtime_entries.resolve_entries(self.client_module_context()))
592+
Ok(client_runtime_entries.resolve_entries(Vc::upcast(self.client_module_context())))
570593
}
571594

572595
#[turbo_tasks::function]
@@ -615,7 +638,7 @@ impl PagesProject {
615638

616639
#[turbo_tasks::function]
617640
pub async fn client_main_module(self: Vc<Self>) -> Result<Vc<Box<dyn Module>>> {
618-
let client_module_context = self.client_module_context();
641+
let client_module_context = Vc::upcast(self.client_module_context());
619642

620643
let client_main_module = esm_resolve(
621644
Vc::upcast(PlainResolveOrigin::new(
@@ -722,7 +745,7 @@ impl PageEndpoint {
722745
async fn client_module(self: Vc<Self>) -> Result<Vc<Box<dyn Module>>> {
723746
let this = self.await?;
724747
let page_loader = create_page_loader_entry_module(
725-
this.pages_project.client_module_context(),
748+
Vc::upcast(this.pages_project.client_module_context()),
726749
self.source(),
727750
*this.pathname,
728751
);

Diff for: turbopack/crates/turbopack/src/transition/context_transition.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@ use turbo_tasks::{ResolvedVc, Vc};
33
use turbopack_core::compile_time_info::CompileTimeInfo;
44
use turbopack_resolve::resolve_options_context::ResolveOptionsContext;
55

6-
use crate::{module_options::ModuleOptionsContext, transition::Transition};
6+
use crate::{
7+
module_options::ModuleOptionsContext,
8+
transition::{Transition, TransitionOptions},
9+
};
710

811
/// A transition that only affects the asset context.
912
#[turbo_tasks::value(shared)]
1013
pub struct ContextTransition {
1114
compile_time_info: ResolvedVc<CompileTimeInfo>,
1215
module_options_context: ResolvedVc<ModuleOptionsContext>,
1316
resolve_options_context: ResolvedVc<ResolveOptionsContext>,
17+
transition_options: ResolvedVc<TransitionOptions>,
1418
layer: ResolvedVc<RcStr>,
1519
}
1620

@@ -21,12 +25,14 @@ impl ContextTransition {
2125
compile_time_info: ResolvedVc<CompileTimeInfo>,
2226
module_options_context: ResolvedVc<ModuleOptionsContext>,
2327
resolve_options_context: ResolvedVc<ResolveOptionsContext>,
28+
transition_options: ResolvedVc<TransitionOptions>,
2429
layer: ResolvedVc<RcStr>,
2530
) -> Vc<ContextTransition> {
2631
ContextTransition {
2732
module_options_context,
2833
resolve_options_context,
2934
compile_time_info,
35+
transition_options,
3036
layer,
3137
}
3238
.cell()
@@ -63,4 +69,12 @@ impl Transition for ContextTransition {
6369
) -> Vc<ResolveOptionsContext> {
6470
*self.resolve_options_context
6571
}
72+
73+
#[turbo_tasks::function]
74+
fn process_transition_options(
75+
&self,
76+
_transition_options: Vc<TransitionOptions>,
77+
) -> Vc<TransitionOptions> {
78+
*self.transition_options
79+
}
6680
}

Diff for: turbopack/crates/turbopack/src/transition/mod.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ pub trait Transition {
5757
resolve_options_context
5858
}
5959

60+
/// Apply modifications/wrapping to the transition options
61+
fn process_transition_options(
62+
self: Vc<Self>,
63+
transition_options: Vc<TransitionOptions>,
64+
) -> Vc<TransitionOptions> {
65+
transition_options
66+
}
67+
6068
/// Apply modifications/wrapping to the final asset
6169
fn process_module(
6270
self: Vc<Self>,
@@ -79,8 +87,9 @@ pub trait Transition {
7987
let resolve_options_context =
8088
self.process_resolve_options_context(*module_asset_context.resolve_options_context);
8189
let layer = self.process_layer(*module_asset_context.layer);
90+
let transition_options = self.process_transition_options(*module_asset_context.transitions);
8291
let module_asset_context = ModuleAssetContext::new(
83-
*module_asset_context.transitions,
92+
transition_options,
8493
compile_time_info,
8594
module_options_context,
8695
resolve_options_context,

0 commit comments

Comments
 (0)