Skip to content

Commit 1e01d06

Browse files
authored
[Turbopack] Remove ssr-data module context (#83626)
SSR data is a special module context for development usecases to help with HMR of pages router pages. This allows us to transform pages to strip the Component export, then the dev server can tell the difference between server side and client side changes which informs what kind of refresh we need to do. Instead, create a new `ReferenceEntrySubType` and configure the `export stripping` transform to trigger using that. This is a better approach since we only need to transform that module instead of putting a lot of dependencies in the new module-context and assert layer. This should be a development time performance improvement for pages router Finally delete a number of the `_runtime_entries` functions for server contexts. These were always empty and were a user of the `ServerContextType::PagesData` enum varient that was being deleted. Closes PACK-4155
1 parent 67ca1e9 commit 1e01d06

File tree

20 files changed

+171
-374
lines changed

20 files changed

+171
-374
lines changed

crates/next-api/src/app.rs

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use next_core::{
1212
get_app_page_entry, get_app_route_entry, metadata::route::get_app_metadata_route_entry,
1313
},
1414
next_client::{
15-
ClientContextType, RuntimeEntries, get_client_module_options_context,
16-
get_client_resolve_options_context, get_client_runtime_entries,
15+
ClientContextType, get_client_module_options_context, get_client_resolve_options_context,
16+
get_client_runtime_entries,
1717
},
1818
next_client_reference::{
1919
ClientReferenceGraphResult, NextCssClientReferenceTransition,
@@ -29,7 +29,6 @@ use next_core::{
2929
},
3030
next_server::{
3131
ServerContextType, get_server_module_options_context, get_server_resolve_options_context,
32-
get_server_runtime_entries,
3332
},
3433
next_server_utility::{NEXT_SERVER_UTILITY_MERGE_TAG, NextServerUtilityTransition},
3534
parse_segment_config_from_source,
@@ -778,26 +777,6 @@ impl AppProject {
778777
))
779778
}
780779

781-
#[turbo_tasks::function]
782-
async fn runtime_entries(self: Vc<Self>) -> Result<Vc<RuntimeEntries>> {
783-
Ok(get_server_runtime_entries(
784-
self.rsc_ty().owned().await?,
785-
self.project().next_mode(),
786-
))
787-
}
788-
789-
#[turbo_tasks::function]
790-
fn rsc_runtime_entries(self: Vc<Self>) -> Vc<EvaluatableAssets> {
791-
self.runtime_entries()
792-
.resolve_entries(Vc::upcast(self.rsc_module_context()))
793-
}
794-
795-
#[turbo_tasks::function]
796-
fn edge_rsc_runtime_entries(self: Vc<Self>) -> Vc<EvaluatableAssets> {
797-
self.runtime_entries()
798-
.resolve_entries(Vc::upcast(self.edge_rsc_module_context()))
799-
}
800-
801780
#[turbo_tasks::function]
802781
fn client_env(self: Vc<Self>) -> Vc<Box<dyn ProcessEnv>> {
803782
Vc::upcast(CustomProcessEnv::new(
@@ -1780,17 +1759,11 @@ impl AppEndpoint {
17801759
)
17811760
.await?;
17821761

1783-
let edge_rsc_runtime_entries = this.app_project.edge_rsc_runtime_entries().await?;
1784-
let evaluatable_assets = edge_rsc_runtime_entries
1785-
.iter()
1786-
.map(|m| ResolvedVc::upcast(*m))
1787-
.chain(std::iter::once(app_entry.rsc_entry));
1788-
17891762
assets.concatenate(
17901763
chunking_context
17911764
.evaluated_chunk_group_assets(
17921765
app_entry.rsc_entry.ident(),
1793-
ChunkGroup::Entry(evaluatable_assets.collect()),
1766+
ChunkGroup::Entry(vec![app_entry.rsc_entry]),
17941767
module_graph,
17951768
availability_info,
17961769
)
@@ -1799,13 +1772,11 @@ impl AppEndpoint {
17991772
)
18001773
}
18011774
NextRuntime::NodeJs => {
1802-
let mut evaluatable_assets = this.app_project.rsc_runtime_entries().owned().await?;
1803-
18041775
let Some(rsc_entry) = ResolvedVc::try_downcast(app_entry.rsc_entry) else {
18051776
bail!("rsc_entry must be evaluatable");
18061777
};
18071778

1808-
evaluatable_assets.push(rsc_entry);
1779+
let evaluatable_assets = Vc::cell(vec![rsc_entry]);
18091780

18101781
async {
18111782
let mut current_chunks = OutputAssets::empty();
@@ -1909,7 +1880,7 @@ impl AppEndpoint {
19091880
"app{original_name}.js",
19101881
original_name = app_entry.original_name
19111882
))?,
1912-
Vc::cell(evaluatable_assets),
1883+
evaluatable_assets,
19131884
module_graph,
19141885
current_chunks,
19151886
current_availability_info,

crates/next-api/src/instrumentation.rs

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use next_core::{
33
all_assets_from_entries,
44
next_edge::entry::wrap_edge_entry,
55
next_manifests::{InstrumentationDefinition, MiddlewaresManifestV2},
6-
next_server::{ServerContextType, get_server_runtime_entries},
76
};
87
use tracing::Instrument;
98
use turbo_rcstr::{RcStr, rcstr};
@@ -104,26 +103,10 @@ impl InstrumentationEndpoint {
104103

105104
let module_graph = this.project.module_graph(*module);
106105

107-
let evaluatable_assets = get_server_runtime_entries(
108-
ServerContextType::Instrumentation {
109-
app_dir: this.app_dir.clone(),
110-
ecmascript_client_reference_transition_name: this
111-
.ecmascript_client_reference_transition_name
112-
.clone(),
113-
},
114-
this.project.next_mode(),
115-
)
116-
.resolve_entries(*this.asset_context)
117-
.await?
118-
.iter()
119-
.map(|m| ResolvedVc::upcast(*m))
120-
.chain(std::iter::once(module))
121-
.collect();
122-
123106
let edge_chunking_context = this.project.edge_chunking_context(false);
124107
let edge_files: Vc<OutputAssets> = edge_chunking_context.evaluated_chunk_group_assets(
125108
module.ident(),
126-
ChunkGroup::Entry(evaluatable_assets),
109+
ChunkGroup::Entry(vec![module]),
127110
module_graph,
128111
AvailabilityInfo::Root,
129112
);
@@ -150,17 +133,7 @@ impl InstrumentationEndpoint {
150133
.node_root()
151134
.await?
152135
.join("server/instrumentation.js")?,
153-
get_server_runtime_entries(
154-
ServerContextType::Instrumentation {
155-
app_dir: this.app_dir.clone(),
156-
ecmascript_client_reference_transition_name: this
157-
.ecmascript_client_reference_transition_name
158-
.clone(),
159-
},
160-
this.project.next_mode(),
161-
)
162-
.resolve_entries(*this.asset_context)
163-
.with_entry(*module),
136+
Vc::cell(vec![module]),
164137
module_graph,
165138
OutputAssets::empty(),
166139
AvailabilityInfo::Root,

crates/next-api/src/middleware.rs

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use next_core::{
66
middleware::get_middleware_module,
77
next_edge::entry::wrap_edge_entry,
88
next_manifests::{EdgeFunctionDefinition, MiddlewareMatcher, MiddlewaresManifestV2, Regions},
9-
next_server::{ServerContextType, get_server_runtime_entries},
109
parse_segment_config_from_source,
1110
segment_config::ParseSegmentMode,
1211
util::{MiddlewareMatcherKind, NextRuntime},
@@ -111,26 +110,10 @@ impl MiddlewareEndpoint {
111110

112111
let module_graph = this.project.module_graph(*module);
113112

114-
let evaluatable_assets = get_server_runtime_entries(
115-
ServerContextType::Middleware {
116-
app_dir: this.app_dir.clone(),
117-
ecmascript_client_reference_transition_name: this
118-
.ecmascript_client_reference_transition_name
119-
.clone(),
120-
},
121-
this.project.next_mode(),
122-
)
123-
.resolve_entries(*this.asset_context)
124-
.await?
125-
.iter()
126-
.map(|m| ResolvedVc::upcast(*m))
127-
.chain(std::iter::once(module))
128-
.collect();
129-
130113
let edge_chunking_context = this.project.edge_chunking_context(false);
131114
let edge_files = edge_chunking_context.evaluated_chunk_group_assets(
132115
module.ident(),
133-
ChunkGroup::Entry(evaluatable_assets),
116+
ChunkGroup::Entry(vec![module]),
134117
module_graph,
135118
AvailabilityInfo::Root,
136119
);
@@ -156,17 +139,7 @@ impl MiddlewareEndpoint {
156139
.node_root()
157140
.await?
158141
.join("server/middleware.js")?,
159-
get_server_runtime_entries(
160-
ServerContextType::Middleware {
161-
app_dir: this.app_dir.clone(),
162-
ecmascript_client_reference_transition_name: this
163-
.ecmascript_client_reference_transition_name
164-
.clone(),
165-
},
166-
this.project.next_mode(),
167-
)
168-
.resolve_entries(*this.asset_context)
169-
.with_entry(*module),
142+
Vc::cell(vec![module]),
170143
module_graph,
171144
OutputAssets::empty(),
172145
AvailabilityInfo::Root,

0 commit comments

Comments
 (0)