Skip to content

Commit

Permalink
Don't compute all paths for builds
Browse files Browse the repository at this point in the history
  • Loading branch information
mischnic committed Nov 25, 2024
1 parent 1899edd commit dd88cd0
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 33 deletions.
29 changes: 20 additions & 9 deletions crates/next-api/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1638,17 +1638,28 @@ impl Endpoint for AppEndpoint {
.project()
.emit_all_output_assets(Vc::cell(output_assets));

let node_root = this.app_project.project().node_root();
let server_paths = all_server_paths(output_assets, node_root)
let (server_paths, client_paths) = if this
.app_project
.project()
.next_mode()
.await?
.clone_value();
.is_development()
{
let node_root = this.app_project.project().node_root();
let server_paths = all_server_paths(output_assets, node_root)
.await?
.clone_value();

let client_relative_root = this.app_project.project().client_relative_path();
let client_paths = all_paths_in_root(output_assets, client_relative_root)
.into_future()
.instrument(tracing::info_span!("client_paths"))
.await?
.clone_value();
let client_relative_root = this.app_project.project().client_relative_path();
let client_paths = all_paths_in_root(output_assets, client_relative_root)
.into_future()
.instrument(tracing::info_span!("client_paths"))
.await?
.clone_value();
(server_paths, client_paths)
} else {
(vec![], vec![])
};

let written_endpoint = match *output {
AppEndpointOutput::NodeJs { rsc_chunk, .. } => WrittenEndpoint::NodeJs {
Expand Down
12 changes: 8 additions & 4 deletions crates/next-api/src/instrumentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,14 @@ impl Endpoint for InstrumentationEndpoint {
let _ = output_assets.resolve().await?;
let _ = this.project.emit_all_output_assets(Vc::cell(output_assets));

let node_root = this.project.node_root();
let server_paths = all_server_paths(output_assets, node_root)
.await?
.clone_value();
let server_paths = if this.project.next_mode().await?.is_development() {
let node_root = this.project.node_root();
all_server_paths(output_assets, node_root)
.await?
.clone_value()
} else {
vec![]
};

Ok(WrittenEndpoint::Edge {
server_paths,
Expand Down
29 changes: 17 additions & 12 deletions crates/next-api/src/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,18 +279,23 @@ impl Endpoint for MiddlewareEndpoint {
let _ = output_assets.resolve().await?;
let _ = this.project.emit_all_output_assets(Vc::cell(output_assets));

let node_root = this.project.node_root();
let server_paths = all_server_paths(output_assets, node_root)
.await?
.clone_value();

// Middleware could in theory have a client path (e.g. `new URL`).
let client_relative_root = this.project.client_relative_path();
let client_paths = all_paths_in_root(output_assets, client_relative_root)
.into_future()
.instrument(tracing::info_span!("client_paths"))
.await?
.clone_value();
let (server_paths, client_paths) = if this.project.next_mode().await?.is_development() {
let node_root = this.project.node_root();
let server_paths = all_server_paths(output_assets, node_root)
.await?
.clone_value();

// Middleware could in theory have a client path (e.g. `new URL`).
let client_relative_root = this.project.client_relative_path();
let client_paths = all_paths_in_root(output_assets, client_relative_root)
.into_future()
.instrument(tracing::info_span!("client_paths"))
.await?
.clone_value();
(server_paths, client_paths)
} else {
(vec![], vec![])
};

Ok(WrittenEndpoint::Edge {
server_paths,
Expand Down
28 changes: 20 additions & 8 deletions crates/next-api/src/pages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1275,16 +1275,28 @@ impl Endpoint for PageEndpoint {
.emit_all_output_assets(Vc::cell(output_assets));

let node_root = this.pages_project.project().node_root();
let server_paths = all_server_paths(output_assets, node_root)
.await?
.clone_value();

let client_relative_root = this.pages_project.project().client_relative_path();
let client_paths = all_paths_in_root(output_assets, client_relative_root)
.into_future()
.instrument(tracing::info_span!("client_paths"))
let (server_paths, client_paths) = if this
.pages_project
.project()
.next_mode()
.await?
.clone_value();
.is_development()
{
let server_paths = all_server_paths(output_assets, node_root)
.await?
.clone_value();

let client_relative_root = this.pages_project.project().client_relative_path();
let client_paths = all_paths_in_root(output_assets, client_relative_root)
.into_future()
.instrument(tracing::info_span!("client_paths"))
.await?
.clone_value();
(server_paths, client_paths)
} else {
(vec![], vec![])
};

let node_root = &node_root.await?;
let written_endpoint = match *output {
Expand Down

0 comments on commit dd88cd0

Please sign in to comment.