Commit a46ce8a2 authored by Niklas Mischkulnig's avatar Niklas Mischkulnig

split up into ssr and rsc paths

parent 7a98924e
...@@ -46,7 +46,8 @@ pub struct NapiWrittenEndpoint { ...@@ -46,7 +46,8 @@ pub struct NapiWrittenEndpoint {
pub r#type: String, pub r#type: String,
pub entry_path: Option<String>, pub entry_path: Option<String>,
pub client_paths: Vec<String>, pub client_paths: Vec<String>,
pub server_paths: Vec<NapiServerPath>, pub rsc_paths: Vec<NapiServerPath>,
pub ssr_paths: Vec<NapiServerPath>,
pub config: NapiEndpointConfig, pub config: NapiEndpointConfig,
} }
...@@ -55,22 +56,26 @@ impl From<Option<EndpointOutputPaths>> for NapiWrittenEndpoint { ...@@ -55,22 +56,26 @@ impl From<Option<EndpointOutputPaths>> for NapiWrittenEndpoint {
match written_endpoint { match written_endpoint {
Some(EndpointOutputPaths::NodeJs { Some(EndpointOutputPaths::NodeJs {
server_entry_path, server_entry_path,
server_paths, rsc_paths,
ssr_paths,
client_paths, client_paths,
}) => Self { }) => Self {
r#type: "nodejs".to_string(), r#type: "nodejs".to_string(),
entry_path: Some(server_entry_path.into_owned()), entry_path: Some(server_entry_path.into_owned()),
client_paths: client_paths.into_iter().map(From::from).collect(), client_paths: client_paths.into_iter().map(From::from).collect(),
server_paths: server_paths.into_iter().map(From::from).collect(), rsc_paths: rsc_paths.into_iter().map(From::from).collect(),
ssr_paths: ssr_paths.into_iter().map(From::from).collect(),
..Default::default() ..Default::default()
}, },
Some(EndpointOutputPaths::Edge { Some(EndpointOutputPaths::Edge {
server_paths, rsc_paths,
ssr_paths,
client_paths, client_paths,
}) => Self { }) => Self {
r#type: "edge".to_string(), r#type: "edge".to_string(),
client_paths: client_paths.into_iter().map(From::from).collect(), client_paths: client_paths.into_iter().map(From::from).collect(),
server_paths: server_paths.into_iter().map(From::from).collect(), rsc_paths: rsc_paths.into_iter().map(From::from).collect(),
ssr_paths: ssr_paths.into_iter().map(From::from).collect(),
..Default::default() ..Default::default()
}, },
Some(EndpointOutputPaths::NotFound) | None => Self { Some(EndpointOutputPaths::NotFound) | None => Self {
......
...@@ -40,8 +40,8 @@ use serde::{Deserialize, Serialize}; ...@@ -40,8 +40,8 @@ use serde::{Deserialize, Serialize};
use tracing::Instrument; use tracing::Instrument;
use turbo_rcstr::{RcStr, rcstr}; use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{ use turbo_tasks::{
Completion, FxIndexSet, NonLocalValue, ResolvedVc, TryJoinIterExt, ValueToString, Vc, Completion, Completions, FxIndexSet, NonLocalValue, ResolvedVc, TryJoinIterExt, ValueToString,
fxindexmap, fxindexset, trace::TraceRawVcs, Vc, fxindexmap, fxindexset, trace::TraceRawVcs,
}; };
use turbo_tasks_env::{CustomProcessEnv, ProcessEnv}; use turbo_tasks_env::{CustomProcessEnv, ProcessEnv};
use turbo_tasks_fs::{File, FileContent, FileSystemPath}; use turbo_tasks_fs::{File, FileContent, FileSystemPath};
...@@ -1200,7 +1200,8 @@ impl AppEndpoint { ...@@ -1200,7 +1200,8 @@ impl AppEndpoint {
let client_relative_path = project.client_relative_path().owned().await?; let client_relative_path = project.client_relative_path().owned().await?;
let server_path = node_root.join("server")?; let server_path = node_root.join("server")?;
let mut server_assets = fxindexset![]; let mut rsc_assets = fxindexset![];
let mut ssr_assets = fxindexset![];
let mut client_assets = fxindexset![]; let mut client_assets = fxindexset![];
// assets to add to the middleware manifest (to be loaded in the edge runtime). // assets to add to the middleware manifest (to be loaded in the edge runtime).
let mut middleware_assets = fxindexset![]; let mut middleware_assets = fxindexset![];
...@@ -1307,7 +1308,7 @@ impl AppEndpoint { ...@@ -1307,7 +1308,7 @@ impl AppEndpoint {
} }
client_assets.extend(entry_client_chunks.iter().copied()); client_assets.extend(entry_client_chunks.iter().copied());
server_assets.extend(entry_ssr_chunks.iter().copied()); ssr_assets.extend(entry_ssr_chunks.iter().copied());
let manifest_path_prefix = &app_entry.original_name; let manifest_path_prefix = &app_entry.original_name;
...@@ -1332,7 +1333,7 @@ impl AppEndpoint { ...@@ -1332,7 +1333,7 @@ impl AppEndpoint {
.to_resolved() .to_resolved()
.await?; .await?;
server_assets.insert(app_build_manifest_output); rsc_assets.insert(app_build_manifest_output);
} }
// polyfill-nomodule.js is a pre-compiled asset distributed as part of next, // polyfill-nomodule.js is a pre-compiled asset distributed as part of next,
...@@ -1381,7 +1382,7 @@ impl AppEndpoint { ...@@ -1381,7 +1382,7 @@ impl AppEndpoint {
) )
.to_resolved() .to_resolved()
.await?; .await?;
server_assets.insert(ResolvedVc::upcast(stats_output)); rsc_assets.insert(ResolvedVc::upcast(stats_output));
} }
let build_manifest = BuildManifest { let build_manifest = BuildManifest {
...@@ -1401,7 +1402,7 @@ impl AppEndpoint { ...@@ -1401,7 +1402,7 @@ impl AppEndpoint {
.to_resolved() .to_resolved()
.await?, .await?,
); );
server_assets.insert(build_manifest_output); rsc_assets.insert(build_manifest_output);
} }
if runtime == NextRuntime::Edge { if runtime == NextRuntime::Edge {
...@@ -1444,7 +1445,7 @@ impl AppEndpoint { ...@@ -1444,7 +1445,7 @@ impl AppEndpoint {
) )
.await?; .await?;
if emit_rsc_manifests { if emit_rsc_manifests {
server_assets.insert(server_action_manifest.manifest); rsc_assets.insert(server_action_manifest.manifest);
} }
let server_action_manifest_loader = server_action_manifest.loader; let server_action_manifest_loader = server_action_manifest.loader;
...@@ -1460,7 +1461,7 @@ impl AppEndpoint { ...@@ -1460,7 +1461,7 @@ impl AppEndpoint {
.to_resolved() .to_resolved()
.await?; .await?;
let app_entry_chunks_ref = app_entry_chunks.await?; let app_entry_chunks_ref = app_entry_chunks.await?;
server_assets.extend(app_entry_chunks_ref.iter().copied()); rsc_assets.extend(app_entry_chunks_ref.iter().copied());
let client_assets = OutputAssets::new(client_assets.iter().map(|asset| **asset).collect()) let client_assets = OutputAssets::new(client_assets.iter().map(|asset| **asset).collect())
.to_resolved() .to_resolved()
...@@ -1486,7 +1487,7 @@ impl AppEndpoint { ...@@ -1486,7 +1487,7 @@ impl AppEndpoint {
}) })
.to_resolved() .to_resolved()
.await?; .await?;
server_assets.insert(entry_manifest); rsc_assets.insert(entry_manifest);
if runtime == NextRuntime::Edge { if runtime == NextRuntime::Edge {
middleware_assets.insert(entry_manifest); middleware_assets.insert(entry_manifest);
} }
...@@ -1504,7 +1505,7 @@ impl AppEndpoint { ...@@ -1504,7 +1505,7 @@ impl AppEndpoint {
true, true,
) )
.await?; .await?;
server_assets.insert(next_font_manifest_output); rsc_assets.insert(next_font_manifest_output);
} }
let endpoint_output = match runtime { let endpoint_output = match runtime {
...@@ -1567,7 +1568,7 @@ impl AppEndpoint { ...@@ -1567,7 +1568,7 @@ impl AppEndpoint {
) )
.await?; .await?;
server_assets.extend(loadable_manifest_output.iter().copied()); rsc_assets.extend(loadable_manifest_output.iter().copied());
file_paths_from_root.extend( file_paths_from_root.extend(
get_js_paths_from_root(&node_root_value, &loadable_manifest_output).await?, get_js_paths_from_root(&node_root_value, &loadable_manifest_output).await?,
); );
...@@ -1618,7 +1619,7 @@ impl AppEndpoint { ...@@ -1618,7 +1619,7 @@ impl AppEndpoint {
.to_resolved() .to_resolved()
.await?, .await?,
); );
server_assets.insert(middleware_manifest_v2); rsc_assets.insert(middleware_manifest_v2);
} }
if emit_manifests != EmitManifests::None { if emit_manifests != EmitManifests::None {
// create app paths manifest // create app paths manifest
...@@ -1628,14 +1629,13 @@ impl AppEndpoint { ...@@ -1628,14 +1629,13 @@ impl AppEndpoint {
entry_file, entry_file,
) )
.await?; .await?;
server_assets.insert(app_paths_manifest_output); rsc_assets.insert(app_paths_manifest_output);
} }
AppEndpointOutput::Edge { AppEndpointOutput::Edge {
files: app_entry_chunks, files: app_entry_chunks,
server_assets: ResolvedVc::cell( rsc_assets: ResolvedVc::cell(rsc_assets.iter().cloned().collect::<Vec<_>>()),
server_assets.iter().cloned().collect::<Vec<_>>(), ssr_assets: ResolvedVc::cell(ssr_assets.iter().cloned().collect::<Vec<_>>()),
),
client_assets, client_assets,
} }
} }
...@@ -1656,7 +1656,7 @@ impl AppEndpoint { ...@@ -1656,7 +1656,7 @@ impl AppEndpoint {
.into(), .into(),
) )
.await?; .await?;
server_assets.insert(app_paths_manifest_output); rsc_assets.insert(app_paths_manifest_output);
} }
let loadable_manifest_output = if emit_manifests == EmitManifests::Full { let loadable_manifest_output = if emit_manifests == EmitManifests::Full {
...@@ -1682,7 +1682,7 @@ impl AppEndpoint { ...@@ -1682,7 +1682,7 @@ impl AppEndpoint {
) )
.await?; .await?;
server_assets.extend(loadable_manifest_output.iter().copied()); rsc_assets.extend(loadable_manifest_output.iter().copied());
Some(loadable_manifest_output) Some(loadable_manifest_output)
} else { } else {
None None
...@@ -1695,7 +1695,7 @@ impl AppEndpoint { ...@@ -1695,7 +1695,7 @@ impl AppEndpoint {
.await? .await?
.is_production() .is_production()
{ {
server_assets.insert(ResolvedVc::upcast( rsc_assets.insert(ResolvedVc::upcast(
NftJsonAsset::new( NftJsonAsset::new(
project, project,
Some(app_function_name(&app_entry.original_name).into()), Some(app_function_name(&app_entry.original_name).into()),
...@@ -1714,9 +1714,8 @@ impl AppEndpoint { ...@@ -1714,9 +1714,8 @@ impl AppEndpoint {
AppEndpointOutput::NodeJs { AppEndpointOutput::NodeJs {
rsc_chunk, rsc_chunk,
server_assets: ResolvedVc::cell( rsc_assets: ResolvedVc::cell(rsc_assets.iter().cloned().collect::<Vec<_>>()),
server_assets.iter().cloned().collect::<Vec<_>>(), ssr_assets: ResolvedVc::cell(ssr_assets.iter().cloned().collect::<Vec<_>>()),
),
client_assets, client_assets,
} }
} }
...@@ -1962,10 +1961,9 @@ impl Endpoint for AppEndpoint { ...@@ -1962,10 +1961,9 @@ impl Endpoint for AppEndpoint {
async move { async move {
let output = self.output(); let output = self.output();
let output_assets = output.output_assets(); let output_assets = output.output_assets();
let output = output.await?;
let node_root = &*this.app_project.project().node_root().await?; let node_root = &*this.app_project.project().node_root().await?;
let (server_paths, client_paths) = if this let (rsc_paths, ssr_paths, client_paths) = if this
.app_project .app_project
.project() .project()
.next_mode() .next_mode()
...@@ -1973,7 +1971,12 @@ impl Endpoint for AppEndpoint { ...@@ -1973,7 +1971,12 @@ impl Endpoint for AppEndpoint {
.is_development() .is_development()
{ {
let node_root = this.app_project.project().node_root().owned().await?; let node_root = this.app_project.project().node_root().owned().await?;
let server_paths = all_server_paths(output_assets, node_root).owned().await?; let rsc_paths = all_server_paths(output.rsc_assets(), node_root.clone())
.owned()
.await?;
let ssr_paths = all_server_paths(output.ssr_assets(), node_root)
.owned()
.await?;
let client_relative_root = this let client_relative_root = this
.app_project .app_project
...@@ -1981,26 +1984,29 @@ impl Endpoint for AppEndpoint { ...@@ -1981,26 +1984,29 @@ impl Endpoint for AppEndpoint {
.client_relative_path() .client_relative_path()
.owned() .owned()
.await?; .await?;
let client_paths = all_paths_in_root(output_assets, client_relative_root) let client_paths = all_paths_in_root(output.client_assets(), client_relative_root)
.owned() .owned()
.instrument(tracing::info_span!("client_paths")) .instrument(tracing::info_span!("client_paths"))
.await?; .await?;
(server_paths, client_paths) (rsc_paths, ssr_paths, client_paths)
} else { } else {
(vec![], vec![]) (vec![], vec![], vec![])
}; };
let output = output.await?;
let written_endpoint = match *output { let written_endpoint = match *output {
AppEndpointOutput::NodeJs { rsc_chunk, .. } => EndpointOutputPaths::NodeJs { AppEndpointOutput::NodeJs { rsc_chunk, .. } => EndpointOutputPaths::NodeJs {
server_entry_path: node_root server_entry_path: node_root
.get_path_to(&*rsc_chunk.path().await?) .get_path_to(&*rsc_chunk.path().await?)
.context("Node.js chunk entry path must be inside the node root")? .context("Node.js chunk entry path must be inside the node root")?
.into(), .into(),
server_paths, rsc_paths,
ssr_paths,
client_paths, client_paths,
}, },
AppEndpointOutput::Edge { .. } => EndpointOutputPaths::Edge { AppEndpointOutput::Edge { .. } => EndpointOutputPaths::Edge {
server_paths, rsc_paths,
ssr_paths,
client_paths, client_paths,
}, },
}; };
...@@ -2021,11 +2027,16 @@ impl Endpoint for AppEndpoint { ...@@ -2021,11 +2027,16 @@ impl Endpoint for AppEndpoint {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn server_changed(self: Vc<Self>) -> Result<Vc<Completion>> { async fn server_changed(self: Vc<Self>) -> Result<Vc<Completion>> {
Ok(self Ok(Completions::all(vec![
.await? self.await?
.app_project .app_project
.project() .project()
.server_changed(self.output().server_assets())) .server_changed(self.output().rsc_assets()),
self.await?
.app_project
.project()
.server_changed(self.output().ssr_assets()),
]))
} }
#[turbo_tasks::function] #[turbo_tasks::function]
...@@ -2100,12 +2111,14 @@ impl Endpoint for AppEndpoint { ...@@ -2100,12 +2111,14 @@ impl Endpoint for AppEndpoint {
enum AppEndpointOutput { enum AppEndpointOutput {
NodeJs { NodeJs {
rsc_chunk: ResolvedVc<Box<dyn OutputAsset>>, rsc_chunk: ResolvedVc<Box<dyn OutputAsset>>,
server_assets: ResolvedVc<OutputAssets>, rsc_assets: ResolvedVc<OutputAssets>,
ssr_assets: ResolvedVc<OutputAssets>,
client_assets: ResolvedVc<OutputAssets>, client_assets: ResolvedVc<OutputAssets>,
}, },
Edge { Edge {
files: ResolvedVc<OutputAssets>, files: ResolvedVc<OutputAssets>,
server_assets: ResolvedVc<OutputAssets>, rsc_assets: ResolvedVc<OutputAssets>,
ssr_assets: ResolvedVc<OutputAssets>,
client_assets: ResolvedVc<OutputAssets>, client_assets: ResolvedVc<OutputAssets>,
}, },
} }
...@@ -2114,22 +2127,31 @@ enum AppEndpointOutput { ...@@ -2114,22 +2127,31 @@ enum AppEndpointOutput {
impl AppEndpointOutput { impl AppEndpointOutput {
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn output_assets(self: Vc<Self>) -> Result<Vc<OutputAssets>> { pub async fn output_assets(self: Vc<Self>) -> Result<Vc<OutputAssets>> {
let server_assets = self.server_assets().await?; let rsc_assets = self.rsc_assets();
let client_assets = self.client_assets().await?; let ssr_assets = self.ssr_assets();
let client_assets = self.client_assets();
Ok(Vc::cell( Ok(Vc::cell(
server_assets [rsc_assets.await?, ssr_assets.await?, client_assets.await?]
.iter() .iter()
.cloned() .flatten()
.chain(client_assets.iter().cloned()) .copied()
.collect(), .collect(),
)) ))
} }
#[turbo_tasks::function] #[turbo_tasks::function]
pub fn server_assets(&self) -> Vc<OutputAssets> { pub fn rsc_assets(&self) -> Vc<OutputAssets> {
match *self {
AppEndpointOutput::NodeJs { rsc_assets, .. }
| AppEndpointOutput::Edge { rsc_assets, .. } => *rsc_assets,
}
}
#[turbo_tasks::function]
pub fn ssr_assets(&self) -> Vc<OutputAssets> {
match *self { match *self {
AppEndpointOutput::NodeJs { server_assets, .. } AppEndpointOutput::NodeJs { ssr_assets, .. }
| AppEndpointOutput::Edge { server_assets, .. } => *server_assets, | AppEndpointOutput::Edge { ssr_assets, .. } => *ssr_assets,
} }
} }
......
...@@ -252,7 +252,8 @@ impl Endpoint for InstrumentationEndpoint { ...@@ -252,7 +252,8 @@ impl Endpoint for InstrumentationEndpoint {
Ok(EndpointOutput { Ok(EndpointOutput {
output_assets: output_assets.to_resolved().await?, output_assets: output_assets.to_resolved().await?,
output_paths: EndpointOutputPaths::Edge { output_paths: EndpointOutputPaths::Edge {
server_paths, rsc_paths: server_paths,
ssr_paths: vec![],
client_paths: vec![], client_paths: vec![],
} }
.resolved_cell(), .resolved_cell(),
......
...@@ -381,7 +381,8 @@ impl Endpoint for MiddlewareEndpoint { ...@@ -381,7 +381,8 @@ impl Endpoint for MiddlewareEndpoint {
Ok(EndpointOutput { Ok(EndpointOutput {
output_paths: EndpointOutputPaths::Edge { output_paths: EndpointOutputPaths::Edge {
server_paths, rsc_paths: server_paths,
ssr_paths: vec![],
client_paths, client_paths,
} }
.resolved_cell(), .resolved_cell(),
......
...@@ -1676,14 +1676,14 @@ impl Endpoint for PageEndpoint { ...@@ -1676,14 +1676,14 @@ impl Endpoint for PageEndpoint {
let node_root = this.pages_project.project().node_root().owned().await?; let node_root = this.pages_project.project().node_root().owned().await?;
let (server_paths, client_paths) = if this let (ssr_paths, client_paths) = if this
.pages_project .pages_project
.project() .project()
.next_mode() .next_mode()
.await? .await?
.is_development() .is_development()
{ {
let server_paths = all_server_paths(output_assets, node_root.clone()) let ssr_paths = all_server_paths(output_assets, node_root.clone())
.owned() .owned()
.await?; .await?;
...@@ -1697,7 +1697,7 @@ impl Endpoint for PageEndpoint { ...@@ -1697,7 +1697,7 @@ impl Endpoint for PageEndpoint {
.owned() .owned()
.instrument(tracing::info_span!("client_paths")) .instrument(tracing::info_span!("client_paths"))
.await?; .await?;
(server_paths, client_paths) (ssr_paths, client_paths)
} else { } else {
(vec![], vec![]) (vec![], vec![])
}; };
...@@ -1718,12 +1718,14 @@ impl Endpoint for PageEndpoint { ...@@ -1718,12 +1718,14 @@ impl Endpoint for PageEndpoint {
EndpointOutputPaths::NodeJs { EndpointOutputPaths::NodeJs {
server_entry_path, server_entry_path,
server_paths, rsc_paths: vec![],
ssr_paths,
client_paths, client_paths,
} }
} }
PageEndpointOutput::Edge { .. } => EndpointOutputPaths::Edge { PageEndpointOutput::Edge { .. } => EndpointOutputPaths::Edge {
server_paths, rsc_paths: vec![],
ssr_paths,
client_paths, client_paths,
}, },
}; };
......
...@@ -148,11 +148,13 @@ pub enum EndpointOutputPaths { ...@@ -148,11 +148,13 @@ pub enum EndpointOutputPaths {
NodeJs { NodeJs {
/// Relative to the root_path /// Relative to the root_path
server_entry_path: RcStr, server_entry_path: RcStr,
server_paths: Vec<ServerPath>, ssr_paths: Vec<ServerPath>,
rsc_paths: Vec<ServerPath>,
client_paths: Vec<RcStr>, client_paths: Vec<RcStr>,
}, },
Edge { Edge {
server_paths: Vec<ServerPath>, ssr_paths: Vec<ServerPath>,
rsc_paths: Vec<ServerPath>,
client_paths: Vec<RcStr>, client_paths: Vec<RcStr>,
}, },
NotFound, NotFound,
......
...@@ -292,6 +292,11 @@ impl ClientReferenceManifest { ...@@ -292,6 +292,11 @@ impl ClientReferenceManifest {
ManifestNodeEntry { ManifestNodeEntry {
name: rcstr!("*"), name: rcstr!("*"),
id: (&*rsc_chunk_item_id).into(), id: (&*rsc_chunk_item_id).into(),
// When a use-cache function runs, it's in the same Node.js context as
// the parent RSC page renderer, so all needed chunks are loaded already
// anyway. So if the use-cache function returns client references in the
// RSC payload that the page context needs, then these modules are
// already loaded.
chunks: vec![], chunks: vec![],
r#async: rsc_is_async, r#async: rsc_is_async,
}, },
......
...@@ -61,7 +61,8 @@ export interface NapiWrittenEndpoint { ...@@ -61,7 +61,8 @@ export interface NapiWrittenEndpoint {
type: string type: string
entryPath?: string entryPath?: string
clientPaths: Array<string> clientPaths: Array<string>
serverPaths: Array<NapiServerPath> rscPaths: Array<NapiServerPath>
ssrPaths: Array<NapiServerPath>
config: NapiEndpointConfig config: NapiEndpointConfig
} }
export declare function endpointWriteToDisk(endpoint: { export declare function endpointWriteToDisk(endpoint: {
......
...@@ -333,22 +333,27 @@ export type WrittenEndpoint = ...@@ -333,22 +333,27 @@ export type WrittenEndpoint =
entryPath: string entryPath: string
/** All client paths that have been written for the endpoint. */ /** All client paths that have been written for the endpoint. */
clientPaths: string[] clientPaths: string[]
/** All server paths that have been written for the endpoint. */ /** All SSR server paths that have been written for the endpoint. */
serverPaths: ServerPath[] ssrPaths: ServerPath[]
/** All RSC server paths that have been written for the endpoint. */
rscPaths: ServerPath[]
config: EndpointConfig config: EndpointConfig
} }
| { | {
type: 'edge' type: 'edge'
/** All client paths that have been written for the endpoint. */ /** All client paths that have been written for the endpoint. */
clientPaths: string[] clientPaths: string[]
/** All server paths that have been written for the endpoint. */ /** All SSR server paths that have been written for the endpoint. */
serverPaths: ServerPath[] ssrPaths: ServerPath[]
/** All RSC server paths that have been written for the endpoint. */
rscPaths: ServerPath[]
config: EndpointConfig config: EndpointConfig
} }
| { | {
type: 'none' type: 'none'
clientPaths: [] clientPaths: []
serverPaths: [] ssrPaths: []
rscPaths: []
config: EndpointConfig config: EndpointConfig
} }
......
...@@ -23,6 +23,7 @@ import type { ...@@ -23,6 +23,7 @@ import type {
TurbopackResult, TurbopackResult,
Project, Project,
Entrypoints, Entrypoints,
ServerPath,
} from '../../build/swc/types' } from '../../build/swc/types'
import { createDefineEnv } from '../../build/swc' import { createDefineEnv } from '../../build/swc'
import * as Log from '../../build/output/log' import * as Log from '../../build/output/log'
...@@ -312,64 +313,77 @@ export async function createHotReloaderTurbopack( ...@@ -312,64 +313,77 @@ export async function createHotReloaderTurbopack(
force?: boolean force?: boolean
} = {} } = {}
): boolean { ): boolean {
if (force) { function shouldClear(paths: ServerPath[]): boolean {
for (const { path, contentHash } of writtenEndpoint.serverPaths) { if (force) {
// We ignore source maps for (const { path, contentHash } of paths) {
if (path.endsWith('.map')) continue // We ignore source maps
const localKey = `${key}:${path}` if (path.endsWith('.map')) continue
serverPathState.set(localKey, contentHash) const localKey = `${key}:${path}`
serverPathState.set(path, contentHash)
}
} else {
// Figure out if the server files have changed
let hasChange = false
for (const { path, contentHash } of writtenEndpoint.serverPaths) {
// We ignore source maps
if (path.endsWith('.map')) continue
const localKey = `${key}:${path}`
const localHash = serverPathState.get(localKey)
const globalHash = serverPathState.get(path)
if (
(localHash && localHash !== contentHash) ||
(globalHash && globalHash !== contentHash)
) {
hasChange = true
serverPathState.set(localKey, contentHash) serverPathState.set(localKey, contentHash)
serverPathState.set(path, contentHash) serverPathState.set(path, contentHash)
} else { }
if (!localHash) { return true
} else {
// Figure out if the server files have changed
let hasChange = false
for (const { path, contentHash } of paths) {
// We ignore source maps
if (path.endsWith('.map')) continue
const localKey = `${key}:${path}`
const localHash = serverPathState.get(localKey)
const globalHash = serverPathState.get(path)
if (
(localHash && localHash !== contentHash) ||
(globalHash && globalHash !== contentHash)
) {
hasChange = true
serverPathState.set(localKey, contentHash) serverPathState.set(localKey, contentHash)
}
if (!globalHash) {
serverPathState.set(path, contentHash) serverPathState.set(path, contentHash)
} else {
if (!localHash) {
serverPathState.set(localKey, contentHash)
}
if (!globalHash) {
serverPathState.set(path, contentHash)
}
} }
} }
}
if (!hasChange) { return hasChange
return false
} }
} }
resetFetch() let hasCleared = false
for (const paths of [writtenEndpoint.ssrPaths, writtenEndpoint.rscPaths]) {
let x = shouldClear(paths)
console.log(
key,
x,
paths === writtenEndpoint.ssrPaths ? 'ssr' : 'rsc',
writtenEndpoint
)
if (x) {
hasCleared = true
// Not available in: resetFetch()
// - Pages Router (no server-side HMR)
// - Edge Runtime (uses browser runtime which already disposes chunks individually)
if (typeof __next__clear_chunk_cache__ === 'function') {
__next__clear_chunk_cache__()
}
const serverPaths = writtenEndpoint.serverPaths.map(({ path: p }) => // Not available in:
join(distDir, p) // - Pages Router (no server-side HMR)
) // - Edge Runtime (uses browser runtime which already disposes chunks individually)
if (typeof __next__clear_chunk_cache__ === 'function') {
__next__clear_chunk_cache__()
}
const serverPaths = paths.map(({ path: p }) => join(distDir, p))
for (const file of serverPaths) { for (const file of serverPaths) {
clearModuleContext(file) clearModuleContext(file)
deleteCache(file) deleteCache(file)
}
}
} }
return true return hasCleared
} }
const buildingIds = new Set() const buildingIds = new Set()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment