Skip to content

Commit 0b1b0ed

Browse files
committed
change how pagesdata entrypoints are created
1 parent 7f743ae commit 0b1b0ed

File tree

14 files changed

+119
-184
lines changed

14 files changed

+119
-184
lines changed

crates/next-api/src/pages.rs

Lines changed: 17 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -402,17 +402,6 @@ impl PagesProject {
402402
)
403403
}
404404

405-
#[turbo_tasks::function]
406-
pub(super) fn ssr_data_module_context(self: Vc<Self>) -> Vc<ModuleAssetContext> {
407-
ModuleAssetContext::new(
408-
self.server_transitions(),
409-
self.project().server_compile_time_info(),
410-
self.ssr_data_module_options_context(),
411-
self.ssr_resolve_options_context(),
412-
Layer::new(rcstr!("ssr-data")),
413-
)
414-
}
415-
416405
#[turbo_tasks::function]
417406
pub(super) fn edge_ssr_module_context(self: Vc<Self>) -> Vc<ModuleAssetContext> {
418407
ModuleAssetContext::new(
@@ -435,17 +424,6 @@ impl PagesProject {
435424
)
436425
}
437426

438-
#[turbo_tasks::function]
439-
pub(super) fn edge_ssr_data_module_context(self: Vc<Self>) -> Vc<ModuleAssetContext> {
440-
ModuleAssetContext::new(
441-
Default::default(),
442-
self.project().edge_compile_time_info(),
443-
self.edge_ssr_data_module_options_context(),
444-
self.edge_ssr_resolve_options_context(),
445-
Layer::new(rcstr!("edge-ssr-data")),
446-
)
447-
}
448-
449427
#[turbo_tasks::function]
450428
async fn ssr_module_options_context(self: Vc<Self>) -> Result<Vc<ModuleOptionsContext>> {
451429
Ok(get_server_module_options_context(
@@ -514,42 +492,6 @@ impl PagesProject {
514492
))
515493
}
516494

517-
#[turbo_tasks::function]
518-
async fn ssr_data_module_options_context(self: Vc<Self>) -> Result<Vc<ModuleOptionsContext>> {
519-
Ok(get_server_module_options_context(
520-
self.project().project_path().owned().await?,
521-
self.project().execution_context(),
522-
ServerContextType::PagesData {
523-
pages_dir: self.pages_dir().owned().await?,
524-
},
525-
self.project().next_mode(),
526-
self.project().next_config(),
527-
NextRuntime::NodeJs,
528-
self.project().encryption_key(),
529-
self.project().server_compile_time_info().environment(),
530-
self.project().client_compile_time_info().environment(),
531-
))
532-
}
533-
534-
#[turbo_tasks::function]
535-
async fn edge_ssr_data_module_options_context(
536-
self: Vc<Self>,
537-
) -> Result<Vc<ModuleOptionsContext>> {
538-
Ok(get_server_module_options_context(
539-
self.project().project_path().owned().await?,
540-
self.project().execution_context(),
541-
ServerContextType::PagesData {
542-
pages_dir: self.pages_dir().owned().await?,
543-
},
544-
self.project().next_mode(),
545-
self.project().next_config(),
546-
NextRuntime::Edge,
547-
self.project().encryption_key(),
548-
self.project().edge_compile_time_info().environment(),
549-
self.project().client_compile_time_info().environment(),
550-
))
551-
}
552-
553495
#[turbo_tasks::function]
554496
async fn ssr_resolve_options_context(self: Vc<Self>) -> Result<Vc<ResolveOptionsContext>> {
555497
Ok(get_server_resolve_options_context(
@@ -652,7 +594,10 @@ struct PageEndpoint {
652594
enum PageEndpointType {
653595
Api,
654596
Html,
597+
// A development only type that is used in pages router so we can differentiate between
598+
// components changing and server props changing.
655599
Data,
600+
// for _document.js
656601
SsrOnly,
657602
}
658603

@@ -701,8 +646,15 @@ impl PageEndpoint {
701646

702647
#[turbo_tasks::function]
703648
async fn source(&self) -> Result<Vc<Box<dyn Source>>> {
704-
Ok(Vc::upcast(FileSource::new(
649+
Ok(Vc::upcast(FileSource::new_with_query(
705650
self.page.file_path().owned().await?,
651+
// When creating a data endpoint we also create an Html endpoint for the same source
652+
// So add a query parameter to differentiate between the two.
653+
if self.ty == PageEndpointType::Data {
654+
rcstr!("?server-data")
655+
} else {
656+
RcStr::default()
657+
},
706658
)))
707659
}
708660

@@ -873,10 +825,10 @@ impl PageEndpoint {
873825
this.pages_project.edge_ssr_module_context(),
874826
),
875827
PageEndpointType::Data => (
876-
ReferenceType::Entry(EntryReferenceSubType::Page),
828+
ReferenceType::Entry(EntryReferenceSubType::PageData),
877829
this.pages_project.project().project_path().owned().await?,
878-
this.pages_project.ssr_data_module_context(),
879-
this.pages_project.edge_ssr_data_module_context(),
830+
this.pages_project.ssr_module_context(),
831+
this.pages_project.edge_ssr_module_context(),
880832
),
881833
PageEndpointType::Api => (
882834
ReferenceType::Entry(EntryReferenceSubType::PagesApi),
@@ -886,10 +838,6 @@ impl PageEndpoint {
886838
),
887839
};
888840

889-
let ssr_module = module_context
890-
.process(self.source(), reference_type.clone())
891-
.module();
892-
893841
let config =
894842
parse_segment_config_from_source(self.source(), ParseSegmentMode::Base).await?;
895843

@@ -900,6 +848,9 @@ impl PageEndpoint {
900848
// wrapped in the route module, and don't need to be handled as edge runtime as the
901849
// rendering for edge is part of the page bundle.
902850
if this.pathname == "/_app" || this.pathname == "/_document" {
851+
let ssr_module = module_context
852+
.process(self.source(), reference_type)
853+
.module();
903854
InternalSsrChunkModule {
904855
ssr_module: ssr_module.to_resolved().await?,
905856
app_module: None,

crates/next-api/src/project.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1838,18 +1838,16 @@ async fn any_output_changed(
18381838
&& (!server || !asset_path.path.ends_with(".css"))
18391839
&& asset_path.is_inside_ref(&path)
18401840
{
1841-
anyhow::Ok(Some(content_changed(*ResolvedVc::upcast(m))))
1841+
anyhow::Ok(Some(
1842+
content_changed(*ResolvedVc::upcast(m))
1843+
.to_resolved()
1844+
.await?,
1845+
))
18421846
} else {
18431847
Ok(None)
18441848
}
18451849
}
18461850
})
1847-
.map(|v| async move {
1848-
Ok(match v.await? {
1849-
Some(v) => Some(v.to_resolved().await?),
1850-
None => None,
1851-
})
1852-
})
18531851
.try_flat_join()
18541852
.await?;
18551853

crates/next-core/src/next_client/transforms.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,12 @@ pub async fn get_next_client_transforms_rules(
5454
match &context_ty {
5555
ClientContextType::Pages { pages_dir } => {
5656
if !foreign_code {
57-
rules.push(
58-
get_next_pages_transforms_rule(
59-
pages_dir.clone(),
60-
ExportFilter::StripDataExports,
61-
enable_mdx_rs,
62-
)
63-
.await?,
64-
);
57+
rules.push(get_next_pages_transforms_rule(
58+
pages_dir.clone(),
59+
ExportFilter::StripDataExports,
60+
enable_mdx_rs,
61+
vec![],
62+
)?);
6563
rules.push(get_next_disallow_export_all_in_page_rule(
6664
enable_mdx_rs,
6765
pages_dir.clone(),

crates/next-core/src/next_edge/context.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ pub async fn get_edge_resolve_options_context(
124124
ty,
125125
ServerContextType::AppRSC { .. }
126126
| ServerContextType::AppRoute { .. }
127-
| ServerContextType::PagesData { .. }
128127
| ServerContextType::Middleware { .. }
129128
| ServerContextType::Instrumentation { .. }
130129
) {

crates/next-core/src/next_import_map.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,7 @@ pub async fn get_next_server_import_map(
345345

346346
import_map.insert_exact_alias(rcstr!("next/dist/server/require-hook"), external);
347347
match ty {
348-
ServerContextType::Pages { .. }
349-
| ServerContextType::PagesData { .. }
350-
| ServerContextType::PagesApi { .. } => {
348+
ServerContextType::Pages { .. } | ServerContextType::PagesApi { .. } => {
351349
import_map.insert_exact_alias(rcstr!("react"), external);
352350
import_map.insert_wildcard_alias(rcstr!("react/"), external);
353351
import_map.insert_exact_alias(rcstr!("react-dom"), external);
@@ -494,7 +492,6 @@ pub async fn get_next_edge_import_map(
494492

495493
match &ty {
496494
ServerContextType::Pages { .. }
497-
| ServerContextType::PagesData { .. }
498495
| ServerContextType::PagesApi { .. }
499496
| ServerContextType::Middleware { .. }
500497
| ServerContextType::Instrumentation { .. } => {}
@@ -547,7 +544,6 @@ pub async fn get_next_edge_import_map(
547544
| ServerContextType::Middleware { .. }
548545
| ServerContextType::Instrumentation { .. }
549546
| ServerContextType::Pages { .. }
550-
| ServerContextType::PagesData { .. }
551547
| ServerContextType::PagesApi { .. } => {
552548
insert_unsupported_node_internal_aliases(&mut import_map).await?;
553549
}
@@ -705,7 +701,6 @@ async fn insert_next_server_special_aliases(
705701

706702
match &ty {
707703
ServerContextType::Pages { .. } | ServerContextType::PagesApi { .. } => {}
708-
ServerContextType::PagesData { .. } => {}
709704
// the logic closely follows the one in createRSCAliases in webpack-config.ts
710705
ServerContextType::AppSSR { app_dir }
711706
| ServerContextType::AppRSC { app_dir, .. }
@@ -759,8 +754,7 @@ async fn insert_next_server_special_aliases(
759754
},
760755
);
761756
}
762-
ServerContextType::PagesData { .. }
763-
| ServerContextType::PagesApi { .. }
757+
ServerContextType::PagesApi { .. }
764758
| ServerContextType::AppRSC { .. }
765759
| ServerContextType::AppRoute { .. }
766760
| ServerContextType::Middleware { .. }
@@ -1243,11 +1237,12 @@ async fn insert_next_shared_aliases(
12431237

12441238
#[turbo_tasks::function]
12451239
pub async fn get_next_package(context_directory: FileSystemPath) -> Result<Vc<FileSystemPath>> {
1240+
let root = context_directory.root().owned().await?;
12461241
let result = resolve(
1247-
context_directory.clone(),
1242+
context_directory,
12481243
ReferenceType::CommonJs(CommonJsReferenceSubType::Undefined),
12491244
Request::parse(Pattern::Constant(rcstr!("next/package.json"))),
1250-
node_cjs_resolve_options(context_directory.root().owned().await?),
1245+
node_cjs_resolve_options(root),
12511246
);
12521247
let source = result
12531248
.first_source()

crates/next-core/src/next_pages/page_entry.rs

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ pub async fn create_page_ssr_entry_module(
5151
.await?;
5252

5353
let template_file = match (&reference_type, runtime) {
54-
(ReferenceType::Entry(EntryReferenceSubType::Page), _) => {
54+
(ReferenceType::Entry(EntryReferenceSubType::Page), _)
55+
| (ReferenceType::Entry(EntryReferenceSubType::PageData), _) => {
5556
// Load the Page entry file.
5657
"pages.js"
5758
}
@@ -77,7 +78,9 @@ pub async fn create_page_ssr_entry_module(
7778
("VAR_USERLAND", &inner),
7879
];
7980

80-
if reference_type == ReferenceType::Entry(EntryReferenceSubType::Page) {
81+
if reference_type == ReferenceType::Entry(EntryReferenceSubType::Page)
82+
|| reference_type == ReferenceType::Entry(EntryReferenceSubType::PageData)
83+
{
8184
replacements.push(("VAR_MODULE_DOCUMENT", &inner_document));
8285
replacements.push(("VAR_MODULE_APP", &inner_app));
8386
}
@@ -89,7 +92,8 @@ pub async fn create_page_ssr_entry_module(
8992
// When we're building the instrumentation page (only when the
9093
// instrumentation file conflicts with a page also labeled
9194
// /instrumentation) hoist the `register` method.
92-
if reference_type == ReferenceType::Entry(EntryReferenceSubType::Page)
95+
if (reference_type == ReferenceType::Entry(EntryReferenceSubType::Page)
96+
|| reference_type == ReferenceType::Entry(EntryReferenceSubType::PageData))
9397
&& (definition_page == "/instrumentation" || definition_page == "/src/instrumentation")
9498
{
9599
let file = &*file_content_rope(source.content().file_content()).await?;
@@ -116,28 +120,30 @@ pub async fn create_page_ssr_entry_module(
116120

117121
let pages_structure_ref = pages_structure.await?;
118122

119-
let (app_module, document_module) =
120-
if reference_type == ReferenceType::Entry(EntryReferenceSubType::Page) {
121-
let document_module = process_global_item(
122-
*pages_structure_ref.document,
123-
reference_type.clone(),
124-
ssr_module_context,
125-
)
126-
.to_resolved()
127-
.await?;
128-
let app_module = process_global_item(
129-
*pages_structure_ref.app,
130-
reference_type.clone(),
131-
ssr_module_context,
132-
)
133-
.to_resolved()
134-
.await?;
135-
inner_assets.insert(inner_document, document_module);
136-
inner_assets.insert(inner_app, app_module);
137-
(Some(app_module), Some(document_module))
138-
} else {
139-
(None, None)
140-
};
123+
let (app_module, document_module) = if reference_type
124+
== ReferenceType::Entry(EntryReferenceSubType::Page)
125+
|| reference_type == ReferenceType::Entry(EntryReferenceSubType::PageData)
126+
{
127+
let document_module = process_global_item(
128+
*pages_structure_ref.document,
129+
reference_type.clone(),
130+
ssr_module_context,
131+
)
132+
.to_resolved()
133+
.await?;
134+
let app_module = process_global_item(
135+
*pages_structure_ref.app,
136+
reference_type.clone(),
137+
ssr_module_context,
138+
)
139+
.to_resolved()
140+
.await?;
141+
inner_assets.insert(inner_document, document_module);
142+
inner_assets.insert(inner_app, app_module);
143+
(Some(app_module), Some(document_module))
144+
} else {
145+
(None, None)
146+
};
141147

142148
let mut ssr_module = ssr_module_context
143149
.process(
@@ -147,7 +153,9 @@ pub async fn create_page_ssr_entry_module(
147153
.module();
148154

149155
if matches!(runtime, NextRuntime::Edge) {
150-
if reference_type == ReferenceType::Entry(EntryReferenceSubType::Page) {
156+
if reference_type == ReferenceType::Entry(EntryReferenceSubType::Page)
157+
|| reference_type == ReferenceType::Entry(EntryReferenceSubType::PageData)
158+
{
151159
ssr_module = wrap_edge_page(
152160
ssr_module_context,
153161
project_root,

crates/next-core/src/next_root_params/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,7 @@ impl NextRootParamsMapper {
111111
})?;
112112
Self::valid_import_map_result(collected_root_params)
113113
}
114-
ServerContextType::PagesData { .. }
115-
| ServerContextType::PagesApi { .. }
114+
ServerContextType::PagesApi { .. }
116115
| ServerContextType::Instrumentation { .. }
117116
| ServerContextType::Middleware { .. } => {
118117
// There's no sensible way to use root params outside of the app

0 commit comments

Comments
 (0)