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 {
pub r#type: String,
pub entry_path: Option<String>,
pub client_paths: Vec<String>,
pub server_paths: Vec<NapiServerPath>,
pub rsc_paths: Vec<NapiServerPath>,
pub ssr_paths: Vec<NapiServerPath>,
pub config: NapiEndpointConfig,
}
......@@ -55,22 +56,26 @@ impl From<Option<EndpointOutputPaths>> for NapiWrittenEndpoint {
match written_endpoint {
Some(EndpointOutputPaths::NodeJs {
server_entry_path,
server_paths,
rsc_paths,
ssr_paths,
client_paths,
}) => Self {
r#type: "nodejs".to_string(),
entry_path: Some(server_entry_path.into_owned()),
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()
},
Some(EndpointOutputPaths::Edge {
server_paths,
rsc_paths,
ssr_paths,
client_paths,
}) => Self {
r#type: "edge".to_string(),
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()
},
Some(EndpointOutputPaths::NotFound) | None => Self {
......
This diff is collapsed.
......@@ -252,7 +252,8 @@ impl Endpoint for InstrumentationEndpoint {
Ok(EndpointOutput {
output_assets: output_assets.to_resolved().await?,
output_paths: EndpointOutputPaths::Edge {
server_paths,
rsc_paths: server_paths,
ssr_paths: vec![],
client_paths: vec![],
}
.resolved_cell(),
......
......@@ -381,7 +381,8 @@ impl Endpoint for MiddlewareEndpoint {
Ok(EndpointOutput {
output_paths: EndpointOutputPaths::Edge {
server_paths,
rsc_paths: server_paths,
ssr_paths: vec![],
client_paths,
}
.resolved_cell(),
......
......@@ -1676,14 +1676,14 @@ impl Endpoint for PageEndpoint {
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
.project()
.next_mode()
.await?
.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()
.await?;
......@@ -1697,7 +1697,7 @@ impl Endpoint for PageEndpoint {
.owned()
.instrument(tracing::info_span!("client_paths"))
.await?;
(server_paths, client_paths)
(ssr_paths, client_paths)
} else {
(vec![], vec![])
};
......@@ -1718,12 +1718,14 @@ impl Endpoint for PageEndpoint {
EndpointOutputPaths::NodeJs {
server_entry_path,
server_paths,
rsc_paths: vec![],
ssr_paths,
client_paths,
}
}
PageEndpointOutput::Edge { .. } => EndpointOutputPaths::Edge {
server_paths,
rsc_paths: vec![],
ssr_paths,
client_paths,
},
};
......
......@@ -148,11 +148,13 @@ pub enum EndpointOutputPaths {
NodeJs {
/// Relative to the root_path
server_entry_path: RcStr,
server_paths: Vec<ServerPath>,
ssr_paths: Vec<ServerPath>,
rsc_paths: Vec<ServerPath>,
client_paths: Vec<RcStr>,
},
Edge {
server_paths: Vec<ServerPath>,
ssr_paths: Vec<ServerPath>,
rsc_paths: Vec<ServerPath>,
client_paths: Vec<RcStr>,
},
NotFound,
......
......@@ -292,6 +292,11 @@ impl ClientReferenceManifest {
ManifestNodeEntry {
name: rcstr!("*"),
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![],
r#async: rsc_is_async,
},
......
......@@ -61,7 +61,8 @@ export interface NapiWrittenEndpoint {
type: string
entryPath?: string
clientPaths: Array<string>
serverPaths: Array<NapiServerPath>
rscPaths: Array<NapiServerPath>
ssrPaths: Array<NapiServerPath>
config: NapiEndpointConfig
}
export declare function endpointWriteToDisk(endpoint: {
......
......@@ -333,22 +333,27 @@ export type WrittenEndpoint =
entryPath: string
/** All client paths that have been written for the endpoint. */
clientPaths: string[]
/** All server paths that have been written for the endpoint. */
serverPaths: ServerPath[]
/** All SSR server paths that have been written for the endpoint. */
ssrPaths: ServerPath[]
/** All RSC server paths that have been written for the endpoint. */
rscPaths: ServerPath[]
config: EndpointConfig
}
| {
type: 'edge'
/** All client paths that have been written for the endpoint. */
clientPaths: string[]
/** All server paths that have been written for the endpoint. */
serverPaths: ServerPath[]
/** All SSR server paths that have been written for the endpoint. */
ssrPaths: ServerPath[]
/** All RSC server paths that have been written for the endpoint. */
rscPaths: ServerPath[]
config: EndpointConfig
}
| {
type: 'none'
clientPaths: []
serverPaths: []
ssrPaths: []
rscPaths: []
config: EndpointConfig
}
......
......@@ -23,6 +23,7 @@ import type {
TurbopackResult,
Project,
Entrypoints,
ServerPath,
} from '../../build/swc/types'
import { createDefineEnv } from '../../build/swc'
import * as Log from '../../build/output/log'
......@@ -312,64 +313,77 @@ export async function createHotReloaderTurbopack(
force?: boolean
} = {}
): boolean {
if (force) {
for (const { path, contentHash } of writtenEndpoint.serverPaths) {
// We ignore source maps
if (path.endsWith('.map')) continue
const localKey = `${key}:${path}`
serverPathState.set(localKey, contentHash)
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
function shouldClear(paths: ServerPath[]): boolean {
if (force) {
for (const { path, contentHash } of paths) {
// We ignore source maps
if (path.endsWith('.map')) continue
const localKey = `${key}:${path}`
serverPathState.set(localKey, 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)
}
if (!globalHash) {
serverPathState.set(path, contentHash)
} else {
if (!localHash) {
serverPathState.set(localKey, contentHash)
}
if (!globalHash) {
serverPathState.set(path, contentHash)
}
}
}
}
if (!hasChange) {
return false
return hasChange
}
}
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:
// - 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__()
}
resetFetch()
const serverPaths = writtenEndpoint.serverPaths.map(({ path: p }) =>
join(distDir, p)
)
// Not available in:
// - 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) {
clearModuleContext(file)
deleteCache(file)
for (const file of serverPaths) {
clearModuleContext(file)
deleteCache(file)
}
}
}
return true
return hasCleared
}
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