Skip to content

Commit

Permalink
Merge branch 'canary' into shu/5348
Browse files Browse the repository at this point in the history
  • Loading branch information
shuding authored Oct 24, 2023
2 parents 2ffbae0 + 69388a5 commit d41104c
Show file tree
Hide file tree
Showing 89 changed files with 1,777 additions and 804 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
"registry": "https://registry.npmjs.org/"
}
},
"version": "13.5.7-canary.19"
"version": "13.5.7-canary.20"
}
2 changes: 1 addition & 1 deletion packages/create-next-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-next-app",
"version": "13.5.7-canary.19",
"version": "13.5.7-canary.20",
"keywords": [
"react",
"next",
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-config-next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-config-next",
"version": "13.5.7-canary.19",
"version": "13.5.7-canary.20",
"description": "ESLint configuration used by Next.js.",
"main": "index.js",
"license": "MIT",
Expand All @@ -10,7 +10,7 @@
},
"homepage": "https://nextjs.org/docs/app/building-your-application/configuring/eslint#eslint-config",
"dependencies": {
"@next/eslint-plugin-next": "13.5.7-canary.19",
"@next/eslint-plugin-next": "13.5.7-canary.20",
"@rushstack/eslint-patch": "^1.3.3",
"@typescript-eslint/parser": "^5.4.2 || ^6.0.0",
"eslint-import-resolver-node": "^0.3.6",
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/eslint-plugin-next",
"version": "13.5.7-canary.19",
"version": "13.5.7-canary.20",
"description": "ESLint plugin for Next.js.",
"main": "dist/index.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/font/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/font",
"version": "13.5.7-canary.19",
"version": "13.5.7-canary.20",
"repository": {
"url": "vercel/next.js",
"directory": "packages/font"
Expand Down
2 changes: 1 addition & 1 deletion packages/next-bundle-analyzer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/bundle-analyzer",
"version": "13.5.7-canary.19",
"version": "13.5.7-canary.20",
"main": "index.js",
"types": "index.d.ts",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-codemod/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/codemod",
"version": "13.5.7-canary.19",
"version": "13.5.7-canary.20",
"license": "MIT",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-env/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/env",
"version": "13.5.7-canary.19",
"version": "13.5.7-canary.20",
"keywords": [
"react",
"next",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-mdx/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/mdx",
"version": "13.5.7-canary.19",
"version": "13.5.7-canary.20",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/next-plugin-storybook/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/plugin-storybook",
"version": "13.5.7-canary.19",
"version": "13.5.7-canary.20",
"repository": {
"url": "vercel/next.js",
"directory": "packages/next-plugin-storybook"
Expand Down
2 changes: 1 addition & 1 deletion packages/next-polyfill-module/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/polyfill-module",
"version": "13.5.7-canary.19",
"version": "13.5.7-canary.20",
"description": "A standard library polyfill for ES Modules supporting browsers (Edge 16+, Firefox 60+, Chrome 61+, Safari 10.1+)",
"main": "dist/polyfill-module.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-polyfill-nomodule/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/polyfill-nomodule",
"version": "13.5.7-canary.19",
"version": "13.5.7-canary.20",
"description": "A polyfill for non-dead, nomodule browsers.",
"main": "dist/polyfill-nomodule.js",
"license": "MIT",
Expand Down
108 changes: 91 additions & 17 deletions packages/next-swc/crates/next-api/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,17 @@ impl AppProject {
ECMASCRIPT_CLIENT_TRANSITION_NAME.to_string(),
Vc::upcast(NextEcmascriptClientReferenceTransition::new(
self.client_transition(),
self.ssr_transition(),
self.edge_ssr_transition(),
)),
),
(
"next-dynamic".to_string(),
Vc::upcast(NextDynamicTransition::new(self.client_transition())),
),
(
"next-ssr".to_string(),
Vc::upcast(self.edge_ssr_transition()),
),
]
.into_iter()
.collect();
Expand Down Expand Up @@ -296,6 +300,18 @@ impl AppProject {
))
}

#[turbo_tasks::function]
async fn edge_ssr_resolve_options_context(self: Vc<Self>) -> Result<Vc<ResolveOptionsContext>> {
let this = self.await?;
Ok(get_edge_resolve_options_context(
self.project().project_path(),
Value::new(self.ssr_ty()),
this.mode,
self.project().next_config(),
self.project().execution_context(),
))
}

#[turbo_tasks::function]
fn ssr_transition(self: Vc<Self>) -> Vc<ContextTransition> {
ContextTransition::new(
Expand All @@ -306,6 +322,16 @@ impl AppProject {
)
}

#[turbo_tasks::function]
fn edge_ssr_transition(self: Vc<Self>) -> Vc<ContextTransition> {
ContextTransition::new(
self.project().edge_compile_time_info(),
self.ssr_module_options_context(),
self.edge_ssr_resolve_options_context(),
Vc::cell("edge_ssr".to_string()),
)
}

#[turbo_tasks::function]
async fn runtime_entries(self: Vc<Self>) -> Result<Vc<RuntimeEntries>> {
let this = self.await?;
Expand Down Expand Up @@ -460,6 +486,7 @@ impl AppEndpoint {
loader_tree,
self.page.clone(),
self.app_project.project().project_path(),
self.app_project.project().next_config(),
)
}

Expand Down Expand Up @@ -519,6 +546,8 @@ impl AppEndpoint {

let mut server_assets = vec![];
let mut client_assets = vec![];
// assets to add to the middleware manifest (to be loaded in the edge runtime).
let mut middleware_assets = vec![];

let app_entry = app_entry.await?;

Expand Down Expand Up @@ -579,11 +608,20 @@ impl AppEndpoint {
.entry(Vc::upcast(app_entry.rsc_entry))
.await?;

let runtime = app_entry.config.await?.runtime.unwrap_or_default();

if ssr_and_client {
let ssr_chunking_context = match runtime {
NextRuntime::NodeJs => {
Vc::upcast(this.app_project.project().server_chunking_context())
}
NextRuntime::Edge => this.app_project.project().edge_chunking_context(),
};

let client_references_chunks = get_app_client_references_chunks(
client_reference_types,
this.app_project.project().client_chunking_context(),
this.app_project.project().server_chunking_context(),
ssr_chunking_context,
);
let client_references_chunks_ref = client_references_chunks.await?;

Expand Down Expand Up @@ -655,13 +693,31 @@ impl AppEndpoint {
client_references,
client_references_chunks,
this.app_project.project().client_chunking_context(),
Vc::upcast(this.app_project.project().server_chunking_context()),
ssr_chunking_context,
this.app_project
.project()
.next_config()
.computed_asset_prefix(),
runtime,
);
server_assets.push(entry_manifest);

if runtime == NextRuntime::Edge {
middleware_assets.push(entry_manifest);

// as the edge runtime doesn't support chunk loading we need to add all client
// references to the middleware manifest so they get loaded during runtime
// initialization
let client_references_chunks = &*client_references_chunks.await?;

for (ty, chunks) in client_references_chunks {
if matches!(ty, ClientReferenceType::EcmascriptClientReference(..)) {
let ssr_chunks = &*chunks.ssr_chunks.await?;

middleware_assets.extend(ssr_chunks);
}
}
}
}

fn create_app_paths_manifest(
Expand Down Expand Up @@ -791,36 +847,54 @@ impl AppEndpoint {
);
server_assets.extend(files.await?.iter().copied());

// the next-edge-ssr-loader templates expect the manifests to be stored in
// global variables defined in these files
//
// they are created in `setup-dev-bundler.ts`
let mut file_paths_from_root = vec![
"server/server-reference-manifest.js".to_string(),
"server/middleware-build-manifest.js".to_string(),
"server/middleware-react-loadable-manifest.js".to_string(),
"server/next-font-manifest.js".to_string(),
];

let node_root_value = node_root.await?;
let files_paths_from_root = files
.await?

let middleware_paths_from_root = middleware_assets
.iter()
.map(move |&file| {
.map({
let node_root_value = node_root_value.clone();
async move {
Ok(node_root_value
.get_path_to(&*file.ident().path().await?)
.map(|path| path.to_string()))
move |&file| {
let node_root_value = node_root_value.clone();
async move {
Ok(node_root_value
.get_path_to(&*file.ident().path().await?)
.map(|path| path.to_string()))
}
}
})
.try_flat_join()
.await?;

let server_path_value = server_path.await?;
let files_paths_from_server = files
file_paths_from_root.extend(middleware_paths_from_root);

let rsc_paths_from_root = files
.await?
.iter()
.map(move |&file| {
let server_path_value = server_path_value.clone();
let node_root_value = node_root_value.clone();
async move {
Ok(server_path_value
Ok(node_root_value
.get_path_to(&*file.ident().path().await?)
.map(|path| path.to_string()))
}
})
.try_flat_join()
.await?;
let base_file = files_paths_from_server[0].to_string();

file_paths_from_root.extend(rsc_paths_from_root);

let entry_file = "app-edge-has-no-entrypoint".to_string();

// create middleware manifest
// TODO(alexkirsz) This should be shared with next build.
Expand All @@ -831,7 +905,7 @@ impl AppEndpoint {
..Default::default()
};
let edge_function_definition = EdgeFunctionDefinition {
files: files_paths_from_root,
files: file_paths_from_root,
name: app_entry.pathname.to_string(),
page: app_entry.original_name.clone(),
regions: app_entry
Expand Down Expand Up @@ -870,7 +944,7 @@ impl AppEndpoint {
ty,
&app_entry.pathname,
&app_entry.original_name,
base_file,
entry_file,
)?;
server_assets.push(app_paths_manifest_output);

Expand Down
19 changes: 17 additions & 2 deletions packages/next-swc/crates/next-api/src/pages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,7 @@ impl PageEndpoint {
self.source(),
this.original_name,
config.runtime,
this.pages_project.project().next_config(),
);

let mut evaluatable_assets = edge_runtime_entries.await?.clone_value();
Expand Down Expand Up @@ -645,6 +646,7 @@ impl PageEndpoint {
self.source(),
this.original_name,
config.runtime,
this.pages_project.project().next_config(),
);

let asset_path = get_asset_path_from_pathname(&this.pathname.await?, ".js");
Expand Down Expand Up @@ -926,8 +928,19 @@ impl PageEndpoint {
}
server_assets.extend(files_value.iter().copied());

// the next-edge-ssr-loader templates expect the manifests to be stored in
// global variables defined in these files
//
// they are created in `setup-dev-bundler.ts`
let mut file_paths_from_root = vec![
"server/server-reference-manifest.js".to_string(),
"server/middleware-build-manifest.js".to_string(),
"server/middleware-react-loadable-manifest.js".to_string(),
"server/next-font-manifest.js".to_string(),
];

let node_root_value = node_root.await?;
let files_paths_from_root: Vec<String> = files_value
let middleware_paths_from_root: Vec<String> = files_value
.iter()
.map(move |&file| {
let node_root_value = node_root_value.clone();
Expand All @@ -940,6 +953,8 @@ impl PageEndpoint {
.try_flat_join()
.await?;

file_paths_from_root.extend(middleware_paths_from_root);

let pathname = this.pathname.await?;
let named_regex = get_named_middleware_regex(&pathname);
let matchers = MiddlewareMatcher {
Expand All @@ -949,7 +964,7 @@ impl PageEndpoint {
};
let original_name = this.original_name.await?;
let edge_function_definition = EdgeFunctionDefinition {
files: files_paths_from_root,
files: file_paths_from_root,
name: pathname.to_string(),
page: original_name.to_string(),
regions: None,
Expand Down
Loading

0 comments on commit d41104c

Please sign in to comment.