server: re-land bundled runtimes (#55139)
see https://github.com/vercel/next.js/pull/52997 also added a fix by @jridgewell to fix turbopack Co-authored-by: Justin Ridgewell <112982+jridgewell@users.noreply.github.com>
This commit is contained in:
parent
5b85a40142
commit
5217e7eb06
160 changed files with 1570 additions and 951 deletions
|
@ -162,7 +162,10 @@
|
|||
},
|
||||
{
|
||||
"files": ["packages/**"],
|
||||
"excludedFiles": ["packages/next/taskfile.js"],
|
||||
"excludedFiles": [
|
||||
"packages/next/taskfile*.js",
|
||||
"packages/next/webpack.config.js"
|
||||
],
|
||||
"rules": {
|
||||
"no-shadow": ["warn", { "builtinGlobals": false }],
|
||||
"import/no-extraneous-dependencies": [
|
||||
|
|
5
bench/basic-app/app/api/app/route.js
Normal file
5
bench/basic-app/app/api/app/route.js
Normal file
|
@ -0,0 +1,5 @@
|
|||
export function GET() {
|
||||
return { name: 'John Doe' }
|
||||
}
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
12
bench/basic-app/app/layout.js
Normal file
12
bench/basic-app/app/layout.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
import React from 'react'
|
||||
|
||||
export default function Layout({ children }) {
|
||||
return (
|
||||
<html>
|
||||
<head>
|
||||
<title>My App</title>
|
||||
</head>
|
||||
<body>{children}</body>
|
||||
</html>
|
||||
)
|
||||
}
|
7
bench/basic-app/app/page.js
Normal file
7
bench/basic-app/app/page.js
Normal file
|
@ -0,0 +1,7 @@
|
|||
import React from 'react'
|
||||
|
||||
export default function Page() {
|
||||
return <h1>My Page</h1>
|
||||
}
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
5
bench/basic-app/next.config.js
Normal file
5
bench/basic-app/next.config.js
Normal file
|
@ -0,0 +1,5 @@
|
|||
module.exports = {
|
||||
experimental: {
|
||||
serverMinification: true,
|
||||
},
|
||||
}
|
3
bench/basic-app/pages/api/index.js
Normal file
3
bench/basic-app/pages/api/index.js
Normal file
|
@ -0,0 +1,3 @@
|
|||
export default function handler(req, res) {
|
||||
res.status(200).json({ name: 'John Doe' })
|
||||
}
|
7
bench/basic-app/pages/pages/index.js
Normal file
7
bench/basic-app/pages/pages/index.js
Normal file
|
@ -0,0 +1,7 @@
|
|||
export default () => 'Hello World'
|
||||
|
||||
export function getServerSideProps() {
|
||||
return {
|
||||
props: {},
|
||||
}
|
||||
}
|
|
@ -2,6 +2,8 @@
|
|||
// the other imports
|
||||
import startOperationStreamHandler from '../internal/operation-stream'
|
||||
|
||||
import 'next/dist/server/node-polyfill-fetch'
|
||||
|
||||
import { join } from 'path'
|
||||
import { parse as parseUrl } from 'node:url'
|
||||
|
||||
|
|
|
@ -3,13 +3,15 @@
|
|||
import startOperationStreamHandler from '../internal/operation-stream'
|
||||
|
||||
import '../polyfill/app-polyfills.ts'
|
||||
// TODO: when actions are supported, this should be removed/changed
|
||||
process.env.__NEXT_PRIVATE_PREBUNDLED_REACT = 'next'
|
||||
import 'next/dist/server/require-hook'
|
||||
|
||||
import type { IncomingMessage } from 'node:http'
|
||||
|
||||
import type { RenderData } from 'types/turbopack'
|
||||
import type { RenderOpts } from 'next/dist/server/app-render/types'
|
||||
|
||||
import { renderToHTMLOrFlight } from 'next/dist/server/app-render/app-render'
|
||||
import { RSC_VARY_HEADER } from 'next/dist/client/components/app-router-headers'
|
||||
import { headersFromEntries, initProxiedHeaders } from '../internal/headers'
|
||||
import { parse, ParsedUrlQuery } from 'node:querystring'
|
||||
|
@ -23,6 +25,10 @@ import { join } from 'node:path'
|
|||
import { nodeFs } from 'next/dist/server/lib/node-fs-methods'
|
||||
import { IncrementalCache } from 'next/dist/server/lib/incremental-cache'
|
||||
|
||||
const {
|
||||
renderToHTMLOrFlight,
|
||||
} = require('next/dist/compiled/next-server/app-page.runtime.dev')
|
||||
|
||||
installRequireAndChunkLoad()
|
||||
|
||||
const MIME_TEXT_HTML_UTF8 = 'text/html; charset=utf-8'
|
||||
|
|
|
@ -6,7 +6,7 @@ import { createFromReadableStream } from 'next/dist/compiled/react-server-dom-we
|
|||
import { callServer } from 'next/dist/client/app-call-server'
|
||||
import { linkGc } from 'next/dist/client/app-link-gc'
|
||||
|
||||
import { HeadManagerContext } from 'next/dist/shared/lib/head-manager-context'
|
||||
import { HeadManagerContext } from 'next/dist/shared/lib/head-manager-context.shared-runtime'
|
||||
|
||||
import { initializeHMR } from '@vercel/turbopack-next/dev/client'
|
||||
|
||||
|
|
|
@ -3,11 +3,12 @@
|
|||
import { IPC } from '@vercel/turbopack-node/ipc/index'
|
||||
|
||||
import 'next/dist/server/node-polyfill-fetch.js'
|
||||
import 'next/dist/server/require-hook'
|
||||
import './shims'
|
||||
|
||||
import type { IncomingMessage, ServerResponse } from 'node:http'
|
||||
|
||||
import { renderToHTML, RenderOpts } from 'next/dist/server/render'
|
||||
import type { RenderOpts } from 'next/dist/server/render'
|
||||
import { getRedirectStatus } from 'next/dist/lib/redirect-status'
|
||||
import { PERMANENT_REDIRECT_STATUS } from 'next/dist/shared/lib/constants'
|
||||
import { buildStaticPaths } from 'next/dist/build/utils'
|
||||
|
@ -21,6 +22,9 @@ import type { RenderData } from 'types/turbopack'
|
|||
import type { ChunkGroup } from 'types/next'
|
||||
import type { NextComponentType } from 'next/types'
|
||||
import { parse } from 'node:querystring'
|
||||
const {
|
||||
renderToHTML,
|
||||
} = require('next/dist/compiled/next-server/pages.runtime.dev')
|
||||
|
||||
const ipc = IPC as Ipc<IpcIncomingMessage, IpcOutgoingMessage>
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ use std::{collections::HashMap, io::Write as _, iter::once};
|
|||
|
||||
use anyhow::{bail, Result};
|
||||
use indexmap::indexmap;
|
||||
use indoc::indoc;
|
||||
use indoc::formatdoc;
|
||||
use serde_json::Value as JsonValue;
|
||||
use turbo_tasks::Vc;
|
||||
use turbopack_binding::{
|
||||
|
@ -964,13 +964,18 @@ impl AppRenderer {
|
|||
.emit();
|
||||
}
|
||||
|
||||
let mut result = RopeBuilder::from(indoc! {"
|
||||
\"TURBOPACK { chunking-type: isolatedParallel; transition: next-edge-server-component }\";
|
||||
let mut result = RopeBuilder::from(
|
||||
formatdoc!(
|
||||
"
|
||||
\"TURBOPACK {{ chunking-type: isolatedParallel; transition: {rsc_transition} }}\";
|
||||
import GlobalErrorMod from \"next/dist/client/components/error-boundary\"
|
||||
const { GlobalError } = GlobalErrorMod;
|
||||
\"TURBOPACK { chunking-type: isolatedParallel; transition: next-edge-server-component }\";
|
||||
const {{ GlobalError }} = GlobalErrorMod;
|
||||
\"TURBOPACK {{ chunking-type: isolatedParallel; transition: {rsc_transition} }}\";
|
||||
import base from \"next/dist/server/app-render/entry-base\"\n
|
||||
"});
|
||||
"
|
||||
)
|
||||
.into_bytes(),
|
||||
);
|
||||
|
||||
for import in loader_tree_module.imports {
|
||||
writeln!(result, "{import}")?;
|
||||
|
|
|
@ -46,7 +46,10 @@ use crate::{
|
|||
get_next_client_resolved_map, mdx_import_source_file,
|
||||
},
|
||||
next_shared::{
|
||||
resolve::{ModuleFeatureReportResolvePlugin, UnsupportedModulesResolvePlugin},
|
||||
resolve::{
|
||||
ModuleFeatureReportResolvePlugin, NextSharedRuntimeResolvePlugin,
|
||||
UnsupportedModulesResolvePlugin,
|
||||
},
|
||||
transforms::{
|
||||
emotion::get_emotion_transform_plugin, get_relay_transform_plugin,
|
||||
styled_components::get_styled_components_transform_plugin,
|
||||
|
@ -148,6 +151,7 @@ pub async fn get_client_resolve_options_context(
|
|||
plugins: vec![
|
||||
Vc::upcast(ModuleFeatureReportResolvePlugin::new(project_path)),
|
||||
Vc::upcast(UnsupportedModulesResolvePlugin::new(project_path)),
|
||||
Vc::upcast(NextSharedRuntimeResolvePlugin::new(project_path)),
|
||||
],
|
||||
..Default::default()
|
||||
};
|
||||
|
|
|
@ -24,7 +24,10 @@ use crate::{
|
|||
next_config::NextConfig,
|
||||
next_import_map::get_next_edge_import_map,
|
||||
next_server::context::ServerContextType,
|
||||
next_shared::resolve::{ModuleFeatureReportResolvePlugin, UnsupportedModulesResolvePlugin},
|
||||
next_shared::resolve::{
|
||||
ModuleFeatureReportResolvePlugin, NextSharedRuntimeResolvePlugin,
|
||||
UnsupportedModulesResolvePlugin,
|
||||
},
|
||||
util::foreign_code_context_condition,
|
||||
};
|
||||
|
||||
|
@ -96,10 +99,9 @@ pub async fn get_edge_resolve_options_context(
|
|||
];
|
||||
|
||||
match ty {
|
||||
ServerContextType::AppRSC { .. } | ServerContextType::AppRoute { .. } => {
|
||||
custom_conditions.push("react-server".to_string())
|
||||
}
|
||||
ServerContextType::Pages { .. }
|
||||
ServerContextType::AppRSC { .. } => custom_conditions.push("react-server".to_string()),
|
||||
ServerContextType::AppRoute { .. }
|
||||
| ServerContextType::Pages { .. }
|
||||
| ServerContextType::PagesData { .. }
|
||||
| ServerContextType::AppSSR { .. }
|
||||
| ServerContextType::Middleware { .. } => {}
|
||||
|
@ -114,6 +116,7 @@ pub async fn get_edge_resolve_options_context(
|
|||
plugins: vec![
|
||||
Vc::upcast(ModuleFeatureReportResolvePlugin::new(project_path)),
|
||||
Vc::upcast(UnsupportedModulesResolvePlugin::new(project_path)),
|
||||
Vc::upcast(NextSharedRuntimeResolvePlugin::new(project_path)),
|
||||
],
|
||||
..Default::default()
|
||||
};
|
||||
|
|
|
@ -58,24 +58,26 @@ impl Transition for NextEdgeRouteTransition {
|
|||
|
||||
#[turbo_tasks::function]
|
||||
async fn process_module(
|
||||
&self,
|
||||
self: Vc<Self>,
|
||||
asset: Vc<Box<dyn Module>>,
|
||||
context: Vc<ModuleAssetContext>,
|
||||
) -> Result<Vc<Box<dyn Module>>> {
|
||||
let new_context = self.process_context(context);
|
||||
let this = self.await?;
|
||||
let new_asset = route_bootstrap(
|
||||
asset,
|
||||
Vc::upcast(context),
|
||||
self.base_path,
|
||||
self.bootstrap_asset,
|
||||
Vc::upcast(new_context),
|
||||
this.base_path,
|
||||
this.bootstrap_asset,
|
||||
Vc::cell(indexmap! {
|
||||
"NAME".to_string() => self.entry_name.clone(),
|
||||
"NAME".to_string() => this.entry_name.clone(),
|
||||
}),
|
||||
);
|
||||
|
||||
let asset = ChunkGroupFilesAsset {
|
||||
module: Vc::upcast(new_asset),
|
||||
client_root: self.output_path,
|
||||
chunking_context: self.edge_chunking_context,
|
||||
client_root: this.output_path,
|
||||
chunking_context: this.edge_chunking_context,
|
||||
runtime_entries: None,
|
||||
};
|
||||
|
||||
|
|
|
@ -216,25 +216,26 @@ pub async fn get_next_server_import_map(
|
|||
let ty = ty.into_value();
|
||||
|
||||
insert_next_server_special_aliases(&mut import_map, ty, mode, NextRuntime::NodeJs).await?;
|
||||
let external = ImportMapping::External(None).cell();
|
||||
let external: Vc<ImportMapping> = ImportMapping::External(None).cell();
|
||||
|
||||
import_map.insert_exact_alias("next/dist/server/require-hook", external);
|
||||
match ty {
|
||||
ServerContextType::Pages { .. } | ServerContextType::PagesData { .. } => {
|
||||
import_map.insert_exact_alias("next", external);
|
||||
import_map.insert_wildcard_alias("next/", external);
|
||||
import_map.insert_exact_alias("react", external);
|
||||
import_map.insert_wildcard_alias("react/", external);
|
||||
import_map.insert_exact_alias("react-dom", external);
|
||||
import_map.insert_wildcard_alias("react-dom/", external);
|
||||
import_map.insert_exact_alias("styled-jsx", external);
|
||||
import_map.insert_wildcard_alias("styled-jsx/", external);
|
||||
import_map.insert_exact_alias("react-server-dom-webpack/", external);
|
||||
import_map.insert_wildcard_alias("react-server-dom-webpack/", external);
|
||||
// TODO: we should not bundle next/dist/build/utils in the pages renderer at all
|
||||
import_map.insert_wildcard_alias("next/dist/build/utils", external);
|
||||
}
|
||||
ServerContextType::AppSSR { .. }
|
||||
| ServerContextType::AppRSC { .. }
|
||||
| ServerContextType::AppRoute { .. } => {
|
||||
match mode {
|
||||
NextMode::Development | NextMode::Build => {
|
||||
NextMode::Build => {
|
||||
import_map.insert_wildcard_alias("next/dist/server/", external);
|
||||
import_map.insert_wildcard_alias("next/dist/shared/", external);
|
||||
}
|
||||
|
@ -242,6 +243,7 @@ pub async fn get_next_server_import_map(
|
|||
// The sandbox can't be bundled and needs to be external
|
||||
import_map.insert_exact_alias("next/dist/server/web/sandbox", external);
|
||||
}
|
||||
NextMode::Development => {}
|
||||
}
|
||||
import_map.insert_exact_alias(
|
||||
"next/head",
|
||||
|
@ -377,6 +379,11 @@ async fn insert_next_server_special_aliases(
|
|||
NextRuntime::Edge => request_to_import_mapping(context_dir, request),
|
||||
NextRuntime::NodeJs => external_request_to_import_mapping(request),
|
||||
};
|
||||
let passthrough_external_if_node =
|
||||
move |context_dir: Vc<FileSystemPath>, request: &str| match runtime {
|
||||
NextRuntime::Edge => request_to_import_mapping(context_dir, request),
|
||||
NextRuntime::NodeJs => ImportMapping::External(None).cell(),
|
||||
};
|
||||
match (mode, ty) {
|
||||
(_, ServerContextType::Pages { pages_dir }) => {
|
||||
import_map.insert_exact_alias(
|
||||
|
@ -413,12 +420,7 @@ async fn insert_next_server_special_aliases(
|
|||
(_, ServerContextType::PagesData { .. }) => {}
|
||||
// In development, we *always* use the bundled version of React, even in
|
||||
// SSR, since we're bundling Next.js alongside it.
|
||||
(
|
||||
NextMode::DevServer,
|
||||
ServerContextType::AppSSR { app_dir }
|
||||
| ServerContextType::AppRSC { app_dir, .. }
|
||||
| ServerContextType::AppRoute { app_dir },
|
||||
) => {
|
||||
(NextMode::DevServer, ServerContextType::AppSSR { app_dir }) => {
|
||||
import_map.insert_exact_alias(
|
||||
"@opentelemetry/api",
|
||||
// TODO(WEB-625) this actually need to prefer the local version of
|
||||
|
@ -427,28 +429,40 @@ async fn insert_next_server_special_aliases(
|
|||
);
|
||||
import_map.insert_exact_alias(
|
||||
"react",
|
||||
request_to_import_mapping(app_dir, "next/dist/compiled/react"),
|
||||
passthrough_external_if_node(app_dir, "next/dist/compiled/react"),
|
||||
);
|
||||
import_map.insert_wildcard_alias(
|
||||
"react/",
|
||||
request_to_import_mapping(app_dir, "next/dist/compiled/react/*"),
|
||||
passthrough_external_if_node(app_dir, "next/dist/compiled/react/*"),
|
||||
);
|
||||
import_map.insert_exact_alias(
|
||||
"react-dom",
|
||||
request_to_import_mapping(
|
||||
passthrough_external_if_node(
|
||||
app_dir,
|
||||
"next/dist/compiled/react-dom/server-rendering-stub.js",
|
||||
),
|
||||
);
|
||||
import_map.insert_wildcard_alias(
|
||||
"react-dom/",
|
||||
request_to_import_mapping(app_dir, "next/dist/compiled/react-dom/*"),
|
||||
passthrough_external_if_node(app_dir, "next/dist/compiled/react-dom/*"),
|
||||
);
|
||||
import_map.insert_exact_alias(
|
||||
"styled-jsx",
|
||||
passthrough_external_if_node(app_dir, "next/dist/compiled/styled-jsx"),
|
||||
);
|
||||
import_map.insert_wildcard_alias(
|
||||
"styled-jsx/",
|
||||
passthrough_external_if_node(app_dir, "next/dist/compiled/styled-jsx/*"),
|
||||
);
|
||||
import_map.insert_wildcard_alias(
|
||||
"react-server-dom-webpack/",
|
||||
request_to_import_mapping(app_dir, "next/dist/compiled/react-server-dom-webpack/*"),
|
||||
passthrough_external_if_node(
|
||||
app_dir,
|
||||
"next/dist/compiled/react-server-dom-webpack/*",
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// NOTE(alexkirsz) This logic maps loosely to
|
||||
// `next.js/packages/next/src/build/webpack-config.ts`, where:
|
||||
//
|
||||
|
@ -460,7 +474,7 @@ async fn insert_next_server_special_aliases(
|
|||
// * passes through (react|react-dom|react-server-dom-webpack)/(.*) to
|
||||
// next/dist/compiled/$1/$2
|
||||
(
|
||||
NextMode::Build | NextMode::Development,
|
||||
NextMode::Build | NextMode::Development | NextMode::DevServer,
|
||||
ServerContextType::AppRSC { app_dir, .. } | ServerContextType::AppRoute { app_dir },
|
||||
) => {
|
||||
import_map.insert_exact_alias(
|
||||
|
@ -469,10 +483,20 @@ async fn insert_next_server_special_aliases(
|
|||
// @opentelemetry/api
|
||||
request_to_import_mapping(app_dir, "next/dist/compiled/@opentelemetry/api"),
|
||||
);
|
||||
import_map.insert_exact_alias(
|
||||
"react",
|
||||
request_to_import_mapping(app_dir, "next/dist/compiled/react/react.shared-subset"),
|
||||
);
|
||||
if matches!(ty, ServerContextType::AppRSC { .. }) {
|
||||
import_map.insert_exact_alias(
|
||||
"react",
|
||||
request_to_import_mapping(
|
||||
app_dir,
|
||||
"next/dist/compiled/react/react.shared-subset",
|
||||
),
|
||||
);
|
||||
} else {
|
||||
import_map.insert_exact_alias(
|
||||
"react",
|
||||
request_to_import_mapping(app_dir, "next/dist/compiled/react"),
|
||||
);
|
||||
}
|
||||
import_map.insert_exact_alias(
|
||||
"react-dom",
|
||||
request_to_import_mapping(
|
||||
|
|
|
@ -46,7 +46,10 @@ use crate::{
|
|||
next_import_map::{get_next_server_import_map, mdx_import_source_file},
|
||||
next_server::resolve::ExternalPredicate,
|
||||
next_shared::{
|
||||
resolve::{ModuleFeatureReportResolvePlugin, UnsupportedModulesResolvePlugin},
|
||||
resolve::{
|
||||
ModuleFeatureReportResolvePlugin, NextExternalResolvePlugin,
|
||||
UnsupportedModulesResolvePlugin,
|
||||
},
|
||||
transforms::{
|
||||
emotion::get_emotion_transform_plugin, get_relay_transform_plugin,
|
||||
styled_components::get_styled_components_transform_plugin,
|
||||
|
@ -108,10 +111,9 @@ pub async fn get_server_resolve_options_context(
|
|||
let mut custom_conditions = vec![mode.node_env().to_string(), "node".to_string()];
|
||||
|
||||
match ty {
|
||||
ServerContextType::AppRSC { .. } | ServerContextType::AppRoute { .. } => {
|
||||
custom_conditions.push("react-server".to_string())
|
||||
}
|
||||
ServerContextType::Pages { .. }
|
||||
ServerContextType::AppRSC { .. } => custom_conditions.push("react-server".to_string()),
|
||||
ServerContextType::AppRoute { .. }
|
||||
| ServerContextType::Pages { .. }
|
||||
| ServerContextType::PagesData { .. }
|
||||
| ServerContextType::AppSSR { .. }
|
||||
| ServerContextType::Middleware { .. } => {}
|
||||
|
@ -121,12 +123,15 @@ pub async fn get_server_resolve_options_context(
|
|||
ExternalPredicate::AllExcept(next_config.transpile_packages()).cell(),
|
||||
);
|
||||
|
||||
let next_external_plugin = NextExternalResolvePlugin::new(project_path);
|
||||
|
||||
let plugins = match ty {
|
||||
ServerContextType::Pages { .. } | ServerContextType::PagesData { .. } => {
|
||||
vec![
|
||||
Vc::upcast(module_feature_report_resolve_plugin),
|
||||
Vc::upcast(external_cjs_modules_plugin),
|
||||
Vc::upcast(unsupported_modules_resolve_plugin),
|
||||
Vc::upcast(next_external_plugin),
|
||||
]
|
||||
}
|
||||
ServerContextType::AppSSR { .. }
|
||||
|
@ -137,6 +142,7 @@ pub async fn get_server_resolve_options_context(
|
|||
Vc::upcast(module_feature_report_resolve_plugin),
|
||||
Vc::upcast(server_component_externals_plugin),
|
||||
Vc::upcast(unsupported_modules_resolve_plugin),
|
||||
Vc::upcast(next_external_plugin),
|
||||
]
|
||||
}
|
||||
};
|
||||
|
|
|
@ -8,12 +8,13 @@ use turbopack_binding::{
|
|||
turbo::tasks_fs::FileSystemPath,
|
||||
turbopack::core::{
|
||||
diagnostics::DiagnosticExt,
|
||||
file_source::FileSource,
|
||||
issue::{unsupported_module::UnsupportedModuleIssue, IssueExt},
|
||||
resolve::{
|
||||
parse::Request,
|
||||
pattern::Pattern,
|
||||
plugin::{ResolvePlugin, ResolvePluginCondition},
|
||||
ResolveResultOption,
|
||||
ResolveResult, ResolveResultItem, ResolveResultOption,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
@ -102,6 +103,55 @@ impl ResolvePlugin for UnsupportedModulesResolvePlugin {
|
|||
}
|
||||
}
|
||||
|
||||
#[turbo_tasks::value]
|
||||
pub(crate) struct NextExternalResolvePlugin {
|
||||
root: Vc<FileSystemPath>,
|
||||
}
|
||||
|
||||
#[turbo_tasks::value_impl]
|
||||
impl NextExternalResolvePlugin {
|
||||
#[turbo_tasks::function]
|
||||
pub fn new(root: Vc<FileSystemPath>) -> Vc<Self> {
|
||||
NextExternalResolvePlugin { root }.cell()
|
||||
}
|
||||
}
|
||||
|
||||
#[turbo_tasks::value_impl]
|
||||
impl ResolvePlugin for NextExternalResolvePlugin {
|
||||
#[turbo_tasks::function]
|
||||
fn after_resolve_condition(&self) -> Vc<ResolvePluginCondition> {
|
||||
ResolvePluginCondition::new(
|
||||
self.root.root(),
|
||||
Glob::new(
|
||||
"**/next/dist/**/*.{external,shared-runtime,runtime.dev,runtime.prod}.js"
|
||||
.to_string(),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
#[turbo_tasks::function]
|
||||
async fn after_resolve(
|
||||
&self,
|
||||
fs_path: Vc<FileSystemPath>,
|
||||
_context: Vc<FileSystemPath>,
|
||||
_request: Vc<Request>,
|
||||
) -> Result<Vc<ResolveResultOption>> {
|
||||
let raw_fs_path = &*fs_path.await?;
|
||||
let path = raw_fs_path.path.to_string();
|
||||
// Find the starting index of 'next/dist' and slice from that point. It should
|
||||
// always be found since the glob pattern above is specific enough.
|
||||
let starting_index = path.find("next/dist").unwrap();
|
||||
// Replace '/esm/' with '/' to match the CJS version of the file.
|
||||
let modified_path = &path[starting_index..].replace("/esm/", "/");
|
||||
Ok(Vc::cell(Some(
|
||||
ResolveResult::primary(ResolveResultItem::OriginalReferenceTypeExternal(
|
||||
modified_path.to_string(),
|
||||
))
|
||||
.into(),
|
||||
)))
|
||||
}
|
||||
}
|
||||
|
||||
/// A resolver plugin tracks the usage of certain import paths, emit
|
||||
/// telemetry events if there is a match.
|
||||
#[turbo_tasks::value]
|
||||
|
@ -154,3 +204,58 @@ impl ResolvePlugin for ModuleFeatureReportResolvePlugin {
|
|||
Ok(ResolveResultOption::none())
|
||||
}
|
||||
}
|
||||
|
||||
#[turbo_tasks::value]
|
||||
pub(crate) struct NextSharedRuntimeResolvePlugin {
|
||||
root: Vc<FileSystemPath>,
|
||||
}
|
||||
|
||||
#[turbo_tasks::value_impl]
|
||||
impl NextSharedRuntimeResolvePlugin {
|
||||
#[turbo_tasks::function]
|
||||
pub fn new(root: Vc<FileSystemPath>) -> Vc<Self> {
|
||||
NextSharedRuntimeResolvePlugin { root }.cell()
|
||||
}
|
||||
}
|
||||
|
||||
#[turbo_tasks::value_impl]
|
||||
impl ResolvePlugin for NextSharedRuntimeResolvePlugin {
|
||||
#[turbo_tasks::function]
|
||||
fn after_resolve_condition(&self) -> Vc<ResolvePluginCondition> {
|
||||
ResolvePluginCondition::new(
|
||||
self.root.root(),
|
||||
Glob::new("**/node_modules/next/dist/**/*.shared-runtime.js".to_string()),
|
||||
)
|
||||
}
|
||||
|
||||
#[turbo_tasks::function]
|
||||
async fn after_resolve(
|
||||
&self,
|
||||
fs_path: Vc<FileSystemPath>,
|
||||
_context: Vc<FileSystemPath>,
|
||||
_request: Vc<Request>,
|
||||
) -> Result<Vc<ResolveResultOption>> {
|
||||
let raw_fs_path = &*fs_path.await?;
|
||||
let path = raw_fs_path.path.to_string();
|
||||
|
||||
// Find the starting index of 'next/dist' and slice from that point. It should
|
||||
// always be found since the glob pattern above is specific enough.
|
||||
let starting_index = path.find("next/dist").unwrap();
|
||||
|
||||
let (base, path) = path.split_at(starting_index);
|
||||
|
||||
// Replace '/esm/' with '/' to match the CJS version of the file.
|
||||
let modified_path = path.replace("/esm/", "/");
|
||||
|
||||
// If there were no replacements, then the original resolved to the CJS module
|
||||
// and we don't need to do anything special
|
||||
if modified_path == path {
|
||||
return Ok(ResolveResultOption::none());
|
||||
}
|
||||
|
||||
let new_path = fs_path.root().join(base.to_string()).join(modified_path);
|
||||
Ok(Vc::cell(Some(
|
||||
ResolveResult::source(Vc::upcast(FileSource::new(new_path))).into(),
|
||||
)))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
warning - [parse] [project]/packages/next/dist/server/web/sandbox/context.js /packages/next/dist/server/web/sandbox/context.js:64:56 lint TP1004 fs.readFile(???*0*) is very dynamic
|
||||
60 | }
|
||||
61 | async function loadWasm(wasm) {
|
||||
62 | const modules = {};
|
||||
63 | await Promise.all(wasm.map(async (binding)=>{
|
||||
+ v
|
||||
64 + const module1 = await WebAssembly.compile(await _fs.promises.readFile(binding.filePath));
|
||||
+ ^
|
||||
65 | modules[binding.name] = module1;
|
||||
66 | }));
|
||||
67 | return modules;
|
||||
68 | }
|
||||
|
||||
- *0* ???*1*["filePath"]
|
||||
⚠️ unknown object
|
||||
- *1* binding
|
||||
⚠️ pattern without value
|
|
@ -0,0 +1,15 @@
|
|||
warning - [parse] [project]/packages/next/dist/server/web/sandbox/context.js /packages/next/dist/server/web/sandbox/context.js:355:28 lint TP1004 fs.readFileSync(???*0*, "utf-8") is very dynamic
|
||||
351 | }
|
||||
352 | const moduleContext = lazyModuleContext;
|
||||
353 | const evaluateInContext = (filepath)=>{
|
||||
354 | if (!moduleContext.paths.has(filepath)) {
|
||||
+ v
|
||||
355 + const content = (0, _fs.readFileSync)(filepath, "utf-8");
|
||||
+ ^
|
||||
356 | try {
|
||||
357 | (0, _vm.runInContext)(content, moduleContext.runtime.context, {
|
||||
358 | filename: filepath
|
||||
359 | });
|
||||
|
||||
- *0* filepath
|
||||
⚠️ pattern without value
|
|
@ -0,0 +1,47 @@
|
|||
error - [rendering] [root of the server]/invalid Error during SSR Rendering
|
||||
Error: Invalid src prop (https://image-optimization-test.vercel.app/test.webp) on `next/image`, hostname "image-optimization-test.vercel.app" is not configured under images in your `next.config.js`
|
||||
|
||||
Debug info:
|
||||
- Error: Invalid src prop (https://image-optimization-test.vercel.app/test.webp) on `next/image`, hostname "image-optimization-test.vercel.app" is not configured under images in your `next.config.js`
|
||||
See more info: https://nextjs.org/docs/messages/next-image-unconfigured-host
|
||||
at defaultLoader (packages/next/dist/shared/lib/image-loader.js:41:27)
|
||||
37 | process.env.NEXT_RUNTIME !== "edge") {
|
||||
38 | // We use dynamic require because this should only error in development
|
||||
39 | const { hasMatch } = require("./match-remote-pattern");
|
||||
40 | if (!hasMatch(config.domains, config.remotePatterns, parsedSrc)) {
|
||||
| v
|
||||
41 + throw new Error("Invalid src prop (" + src + ') on `next/image`, hostname "' + parsedSrc.hostname + '" i...xt.config.js`\n' + "See more info: https://nextjs.org/docs/messages/next-image-unconfigured-host");
|
||||
| ^
|
||||
42 | }
|
||||
43 | }
|
||||
44 | }
|
||||
45 | }
|
||||
|
||||
at <unknown> (packages/next/dist/shared/lib/get-img-props.js:101:36)
|
||||
97 | const { widths , kind } = getWidths(config, width, sizes);
|
||||
98 | const last = widths.length - 1;
|
||||
99 | return {
|
||||
100 | sizes: !sizes && kind === "w" ? "100vw" : sizes,
|
||||
| v
|
||||
101 + srcSet: widths.map((w, i)=>loader({
|
||||
| ^
|
||||
102 | config,
|
||||
103 | src,
|
||||
104 | quality,
|
||||
105 | width: w
|
||||
|
||||
at generateImgAttrs (packages/next/dist/shared/lib/get-img-props.js:101:24)
|
||||
97 | const { widths , kind } = getWidths(config, width, sizes);
|
||||
98 | const last = widths.length - 1;
|
||||
99 | return {
|
||||
100 | sizes: !sizes && kind === "w" ? "100vw" : sizes,
|
||||
| v
|
||||
101 + srcSet: widths.map((w, i)=>loader({
|
||||
| ^
|
||||
102 | config,
|
||||
103 | src,
|
||||
104 | quality,
|
||||
105 | width: w
|
||||
|
||||
at getImgProps (packages/next/dist/shared/lib/get-img-props.js:392:27)
|
||||
at <unknown> (packages/next/dist/client/image-component.js:275:82)
|
|
@ -1,6 +0,0 @@
|
|||
error - [rendering] [root of the server]/invalid Error during SSR Rendering
|
||||
Error: Invalid src prop (https://image-optimization-test.vercel.app/test.webp) on `next/image`, hostname "image-optimization-test.vercel.app" is not configured under images in your `next.config.js`
|
||||
|
||||
Debug info:
|
||||
- Error: Invalid src prop (https://image-optimization-test.vercel.app/test.webp) on `next/image`, hostname "image-optimization-test.vercel.app" is not configured under images in your `next.config.js`
|
||||
See more info: https://nextjs.org/docs/messages/next-image-unconfigured-host
|
|
@ -120,7 +120,7 @@ function runTests() {
|
|||
expect(json).toMatchObject({
|
||||
edgeThenNode: 'node',
|
||||
nodeThenEdge: 'node',
|
||||
reactServer: 'react-server',
|
||||
reactServer: 'default',
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -129,7 +129,7 @@ function runTests() {
|
|||
expect(json).toMatchObject({
|
||||
edgeThenNode: 'edge',
|
||||
nodeThenEdge: 'edge',
|
||||
reactServer: 'react-server',
|
||||
reactServer: 'default',
|
||||
})
|
||||
})
|
||||
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
error - [resolve] [project]/packages/next/dist/compiled/nanoid/index.cjs /packages/next/dist/compiled/nanoid/index.cjs:1:45 Error resolving commonjs request
|
||||
+ v---------------v
|
||||
1 + (()=>{var e={113:e=>{"use strict";e.exports=require("crypto")},660:(e,r,t)=>{let l=t(113);let{urlAlphabet:a}=t(591);const n=128;let _,u;let fillPool=e=>{if(!_||...ndefined")__nccwpck_require__.ab=__dirname+"/";var t=__nccwpck_require__(660);module.exports=t})();
|
||||
+ ^---------------^
|
||||
|
||||
unable to resolve module "crypto"
|
||||
|
||||
| It was not possible to find the requested file.
|
||||
| Parsed request as written in source code: module "crypto"
|
||||
| Path where resolving has started: [project]/packages/next/dist/compiled/nanoid/index.cjs
|
||||
| Type of request: commonjs request
|
||||
| Import map: No import map entry
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
error - [resolve] [project]/packages/next/dist/compiled/nanoid/index.cjs /packages/next/dist/compiled/nanoid/index.cjs:1:45 Error resolving commonjs request
|
||||
+ v---------------v
|
||||
1 + (()=>{var e={113:e=>{"use strict";e.exports=require("crypto")},660:(e,r,t)=>{let l=t(113);let{urlAlphabet:a}=t(591);const n=128;let _,u;let fillPool=e=>{if(!_||...ndefined")__nccwpck_require__.ab=__dirname+"/";var t=__nccwpck_require__(660);module.exports=t})();
|
||||
+ ^---------------^
|
||||
|
||||
unable to resolve module "crypto"
|
||||
|
||||
| It was not possible to find the requested file.
|
||||
| Parsed request as written in source code: module "crypto"
|
||||
| Path where resolving has started: [project]/packages/next/dist/compiled/nanoid/index.cjs
|
||||
| Type of request: commonjs request
|
||||
| Import map: No import map entry
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
warning - [parse] [project]/packages/next/dist/server/web/sandbox/context.js /packages/next/dist/server/web/sandbox/context.js:64:56 lint TP1004 fs.readFile(???*0*) is very dynamic
|
||||
60 | }
|
||||
61 | async function loadWasm(wasm) {
|
||||
62 | const modules = {};
|
||||
63 | await Promise.all(wasm.map(async (binding)=>{
|
||||
+ v
|
||||
64 + const module1 = await WebAssembly.compile(await _fs.promises.readFile(binding.filePath));
|
||||
+ ^
|
||||
65 | modules[binding.name] = module1;
|
||||
66 | }));
|
||||
67 | return modules;
|
||||
68 | }
|
||||
|
||||
- *0* ???*1*["filePath"]
|
||||
⚠️ unknown object
|
||||
- *1* binding
|
||||
⚠️ pattern without value
|
|
@ -0,0 +1,15 @@
|
|||
warning - [parse] [project]/packages/next/dist/server/web/sandbox/context.js /packages/next/dist/server/web/sandbox/context.js:355:28 lint TP1004 fs.readFileSync(???*0*, "utf-8") is very dynamic
|
||||
351 | }
|
||||
352 | const moduleContext = lazyModuleContext;
|
||||
353 | const evaluateInContext = (filepath)=>{
|
||||
354 | if (!moduleContext.paths.has(filepath)) {
|
||||
+ v
|
||||
355 + const content = (0, _fs.readFileSync)(filepath, "utf-8");
|
||||
+ ^
|
||||
356 | try {
|
||||
357 | (0, _vm.runInContext)(content, moduleContext.runtime.context, {
|
||||
358 | filename: filepath
|
||||
359 | });
|
||||
|
||||
- *0* filepath
|
||||
⚠️ pattern without value
|
4
packages/next/config.d.ts
vendored
4
packages/next/config.d.ts
vendored
|
@ -1,3 +1,3 @@
|
|||
import getConfig from './dist/shared/lib/runtime-config'
|
||||
export * from './dist/shared/lib/runtime-config'
|
||||
import getConfig from './dist/shared/lib/runtime-config.shared-runtime'
|
||||
export * from './dist/shared/lib/runtime-config.shared-runtime'
|
||||
export default getConfig
|
||||
|
|
|
@ -1 +1 @@
|
|||
module.exports = require('./dist/shared/lib/runtime-config')
|
||||
module.exports = require('./dist/shared/lib/runtime-config.shared-runtime')
|
||||
|
|
|
@ -83,6 +83,7 @@
|
|||
},
|
||||
"taskr": {
|
||||
"requires": [
|
||||
"./taskfile-webpack.js",
|
||||
"./taskfile-ncc.js",
|
||||
"./taskfile-swc.js",
|
||||
"./taskfile-watch.js"
|
||||
|
@ -299,6 +300,7 @@
|
|||
"tar": "6.1.15",
|
||||
"taskr": "1.1.0",
|
||||
"terser": "5.14.1",
|
||||
"terser-webpack-plugin": "5.3.9",
|
||||
"text-table": "0.2.0",
|
||||
"timers-browserify": "2.0.12",
|
||||
"tty-browserify": "0.0.1",
|
||||
|
|
|
@ -143,8 +143,13 @@ import { createClientRouterFilter } from '../lib/create-client-router-filter'
|
|||
import { createValidFileMatcher } from '../server/lib/find-page-file'
|
||||
import { startTypeChecking } from './type-check'
|
||||
import { generateInterceptionRoutesRewrites } from '../lib/generate-interception-routes-rewrites'
|
||||
|
||||
import { buildDataRoute } from '../server/lib/router-utils/build-data-route'
|
||||
import { baseOverrides, experimentalOverrides } from '../server/require-hook'
|
||||
import {
|
||||
baseOverrides,
|
||||
defaultOverrides,
|
||||
experimentalOverrides,
|
||||
} from '../server/require-hook'
|
||||
import { initialize } from '../server/lib/incremental-cache-server'
|
||||
import { nodeFs } from '../server/lib/node-fs-methods'
|
||||
|
||||
|
@ -1243,6 +1248,7 @@ export default async function build(
|
|||
forkOptions: {
|
||||
env: {
|
||||
...process.env,
|
||||
__NEXT_PRIVATE_RENDER_RUNTIME: type,
|
||||
__NEXT_INCREMENTAL_CACHE_IPC_PORT: ipcPort + '',
|
||||
__NEXT_INCREMENTAL_CACHE_IPC_KEY: ipcValidationKey,
|
||||
__NEXT_PRIVATE_PREBUNDLED_REACT:
|
||||
|
@ -2084,6 +2090,25 @@ export default async function build(
|
|||
...Object.values(experimentalOverrides).map((override) =>
|
||||
require.resolve(override)
|
||||
),
|
||||
...(config.experimental.turbotrace
|
||||
? []
|
||||
: Object.keys(defaultOverrides).map((value) =>
|
||||
require.resolve(value, {
|
||||
paths: [require.resolve('next/dist/server/require-hook')],
|
||||
})
|
||||
)),
|
||||
require.resolve(
|
||||
'next/dist/compiled/next-server/app-page.runtime.prod'
|
||||
),
|
||||
require.resolve(
|
||||
'next/dist/compiled/next-server/app-route.runtime.prod'
|
||||
),
|
||||
require.resolve(
|
||||
'next/dist/compiled/next-server/pages.runtime.prod'
|
||||
),
|
||||
require.resolve(
|
||||
'next/dist/compiled/next-server/pages-api.runtime.prod'
|
||||
),
|
||||
]
|
||||
|
||||
// ensure we trace any dependencies needed for custom
|
||||
|
@ -2109,10 +2134,7 @@ export default async function build(
|
|||
const minimalServerEntries = [
|
||||
...sharedEntriesSet,
|
||||
require.resolve(
|
||||
'next/dist/compiled/minimal-next-server/next-server-cached.js'
|
||||
),
|
||||
require.resolve(
|
||||
'next/dist/compiled/minimal-next-server/next-server.js'
|
||||
'next/dist/compiled/next-server/server.runtime.prod'
|
||||
),
|
||||
].filter(Boolean)
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import type { LoaderTree } from '../../server/lib/app-dir-module'
|
||||
|
||||
// @ts-ignore this need to be imported from next/dist to be external
|
||||
import * as module from 'next/dist/server/future/route-modules/app-page/module'
|
||||
import * as module from 'next/dist/server/future/route-modules/app-page/module.compiled'
|
||||
import { RouteKind } from '../../server/future/route-kind'
|
||||
|
||||
const AppPageRouteModule =
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import '../../server/node-polyfill-headers'
|
||||
|
||||
// @ts-ignore this need to be imported from next/dist to be external
|
||||
import * as module from 'next/dist/server/future/route-modules/app-route/module'
|
||||
import * as module from 'next/dist/server/future/route-modules/app-route/module.compiled'
|
||||
|
||||
import type { AppRouteRouteModuleOptions } from '../../server/future/route-modules/app-route/module'
|
||||
import { RouteKind } from '../../server/future/route-kind'
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
// @ts-ignore this need to be imported from next/dist to be external
|
||||
import * as module from 'next/dist/server/future/route-modules/pages-api/module'
|
||||
import * as module from 'next/dist/server/future/route-modules/pages-api/module.compiled'
|
||||
|
||||
import { RouteKind } from '../../server/future/route-kind'
|
||||
import { hoist } from './helpers'
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// @ts-ignore this need to be imported from next/dist to be external
|
||||
import * as module from 'next/dist/server/future/route-modules/pages/module'
|
||||
import * as module from 'next/dist/server/future/route-modules/pages/module.compiled'
|
||||
import { RouteKind } from '../../server/future/route-kind'
|
||||
import { hoist } from './helpers'
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ import type {
|
|||
EdgeFunctionDefinition,
|
||||
MiddlewareManifest,
|
||||
} from './webpack/plugins/middleware-plugin'
|
||||
import type { StaticGenerationAsyncStorage } from '../client/components/static-generation-async-storage'
|
||||
import type { StaticGenerationAsyncStorage } from '../client/components/static-generation-async-storage.external'
|
||||
|
||||
import '../server/require-hook'
|
||||
import '../server/node-polyfill-fetch'
|
||||
|
@ -65,7 +65,9 @@ import { nodeFs } from '../server/lib/node-fs-methods'
|
|||
import * as ciEnvironment from '../telemetry/ci-info'
|
||||
import { normalizeAppPath } from '../shared/lib/router/utils/app-paths'
|
||||
import { denormalizeAppPagePath } from '../shared/lib/page-path/denormalize-app-path'
|
||||
import { AppRouteRouteModule } from '../server/future/route-modules/app-route/module'
|
||||
// import { AppRouteRouteModule } from '../server/future/route-modules/app-route/module'
|
||||
const { AppRouteRouteModule } =
|
||||
require('../server/future/route-modules/app-route/module.compiled') as typeof import('../server/future/route-modules/app-route/module')
|
||||
|
||||
export type ROUTER_TYPE = 'pages' | 'app'
|
||||
|
||||
|
@ -1407,7 +1409,9 @@ export async function isPageStatic({
|
|||
const isPageStaticSpan = trace('is-page-static-utils', parentId)
|
||||
return isPageStaticSpan
|
||||
.traceAsyncFn(async () => {
|
||||
require('../shared/lib/runtime-config').setConfig(runtimeEnvConfig)
|
||||
require('../shared/lib/runtime-config.shared-runtime').setConfig(
|
||||
runtimeEnvConfig
|
||||
)
|
||||
setHttpClientAndAgentOptions({
|
||||
httpAgentOptions,
|
||||
})
|
||||
|
@ -1691,7 +1695,9 @@ export async function hasCustomGetInitialProps(
|
|||
runtimeEnvConfig: any,
|
||||
checkingApp: boolean
|
||||
): Promise<boolean> {
|
||||
require('../shared/lib/runtime-config').setConfig(runtimeEnvConfig)
|
||||
require('../shared/lib/runtime-config.shared-runtime').setConfig(
|
||||
runtimeEnvConfig
|
||||
)
|
||||
|
||||
const components = await loadComponents({
|
||||
distDir,
|
||||
|
@ -1714,7 +1720,9 @@ export async function getDefinedNamedExports(
|
|||
distDir: string,
|
||||
runtimeEnvConfig: any
|
||||
): Promise<ReadonlyArray<string>> {
|
||||
require('../shared/lib/runtime-config').setConfig(runtimeEnvConfig)
|
||||
require('../shared/lib/runtime-config.shared-runtime').setConfig(
|
||||
runtimeEnvConfig
|
||||
)
|
||||
const components = await loadComponents({
|
||||
distDir,
|
||||
pathname: page,
|
||||
|
|
|
@ -103,6 +103,19 @@ const reactPackagesRegex = /^(react|react-dom|react-server-dom-webpack)($|\/)/
|
|||
const asyncStoragesRegex =
|
||||
/next[\\/]dist[\\/](esm[\\/])?client[\\/]components[\\/](static-generation-async-storage|action-async-storage|request-async-storage)/
|
||||
|
||||
const pathSeparators = '[/\\\\]'
|
||||
const optionalEsmPart = `((${pathSeparators}esm)?${pathSeparators})`
|
||||
const sharedRuntimeFileEnd = '(\\.shared-runtime(\\.js)?)$'
|
||||
const externalFileEnd = '(\\.external(\\.js)?)$'
|
||||
const nextDist = `next${pathSeparators}dist`
|
||||
|
||||
const sharedRuntimePattern = new RegExp(
|
||||
`${nextDist}${optionalEsmPart}.*${sharedRuntimeFileEnd}`
|
||||
)
|
||||
const externalPattern = new RegExp(
|
||||
`${nextDist}${optionalEsmPart}.*${externalFileEnd}`
|
||||
)
|
||||
|
||||
// exports.<conditionName>
|
||||
const edgeConditionNames = [
|
||||
'edge-light',
|
||||
|
@ -1011,7 +1024,7 @@ export default async function getBaseWebpackConfig(
|
|||
const customRootAliases: { [key: string]: string[] } = {}
|
||||
|
||||
if (dev) {
|
||||
const nextDist = 'next/dist/' + (isEdgeServer ? 'esm/' : '')
|
||||
const nextDistPath = 'next/dist/' + (isEdgeServer ? 'esm/' : '')
|
||||
customAppAliases[`${PAGES_DIR_ALIAS}/_app`] = [
|
||||
...(pagesDir
|
||||
? pageExtensions.reduce((prev, ext) => {
|
||||
|
@ -1019,7 +1032,7 @@ export default async function getBaseWebpackConfig(
|
|||
return prev
|
||||
}, [] as string[])
|
||||
: []),
|
||||
`${nextDist}pages/_app.js`,
|
||||
`${nextDistPath}pages/_app.js`,
|
||||
]
|
||||
customAppAliases[`${PAGES_DIR_ALIAS}/_error`] = [
|
||||
...(pagesDir
|
||||
|
@ -1028,7 +1041,7 @@ export default async function getBaseWebpackConfig(
|
|||
return prev
|
||||
}, [] as string[])
|
||||
: []),
|
||||
`${nextDist}pages/_error.js`,
|
||||
`${nextDistPath}pages/_error.js`,
|
||||
]
|
||||
customDocumentAliases[`${PAGES_DIR_ALIAS}/_document`] = [
|
||||
...(pagesDir
|
||||
|
@ -1037,7 +1050,7 @@ export default async function getBaseWebpackConfig(
|
|||
return prev
|
||||
}, [] as string[])
|
||||
: []),
|
||||
`${nextDist}pages/_document.js`,
|
||||
`${nextDistPath}pages/_document.js`,
|
||||
]
|
||||
}
|
||||
|
||||
|
@ -1311,6 +1324,7 @@ export default async function getBaseWebpackConfig(
|
|||
WEBPACK_LAYERS.serverSideRendering,
|
||||
WEBPACK_LAYERS.appPagesBrowser,
|
||||
WEBPACK_LAYERS.actionBrowser,
|
||||
WEBPACK_LAYERS.appRouteHandler,
|
||||
].includes(layer!)
|
||||
|
||||
if (
|
||||
|
@ -1367,7 +1381,7 @@ export default async function getBaseWebpackConfig(
|
|||
}
|
||||
|
||||
const notExternalModules =
|
||||
/^(?:private-next-pages\/|next\/(?:dist\/pages\/|(?:app|document|link|image|legacy\/image|constants|dynamic|script|navigation|headers)$)|string-hash|private-next-rsc-action-validate|private-next-rsc-action-client-wrapper|private-next-rsc-action-proxy$)/
|
||||
/^(?:private-next-pages\/|next\/(?:dist\/pages\/|(?:app|document|link|image|legacy\/image|constants|dynamic|script|navigation|headers|router)$)|string-hash|private-next-rsc-action-validate|private-next-rsc-action-client-wrapper|private-next-rsc-action-proxy$)/
|
||||
if (notExternalModules.test(request)) {
|
||||
return
|
||||
}
|
||||
|
@ -1390,41 +1404,59 @@ export default async function getBaseWebpackConfig(
|
|||
// Also disable esm request when appDir is enabled
|
||||
const isEsmRequested = dependencyType === 'esm'
|
||||
|
||||
/**
|
||||
* @param localRes the full path to the file
|
||||
* @returns the externalized path
|
||||
* @description returns an externalized path if the file is a Next.js file and ends with either `.shared-runtime.js` or `.external.js`
|
||||
* This is used to ensure that files used across the rendering runtime(s) and the user code are one and the same. The logic in this function
|
||||
* will rewrite the require to the correct bundle location depending on the layer at which the file is being used.
|
||||
*/
|
||||
const isLocalCallback = (localRes: string) => {
|
||||
// Makes sure dist/shared and dist/server are not bundled
|
||||
// we need to process shared `router/router`, `head` and `dynamic`,
|
||||
// so that the DefinePlugin can inject process.env values.
|
||||
const isSharedRuntime = sharedRuntimePattern.test(localRes)
|
||||
const isExternal = externalPattern.test(localRes)
|
||||
|
||||
// Treat next internals as non-external for server layer
|
||||
if (isWebpackServerLayer(layer)) {
|
||||
return
|
||||
// if the file ends with .external, we need to make it a commonjs require in all cases
|
||||
// this is used mainly to share the async local storage across the routing, rendering and user layers.
|
||||
if (isExternal) {
|
||||
// it's important we return the path that starts with `next/dist/` here instead of the absolute path
|
||||
// otherwise NFT will get tripped up
|
||||
return `commonjs ${localRes.replace(/.*?next[/\\]dist/, 'next/dist')}`
|
||||
}
|
||||
// if the file ends with .shared-runtime, we need to make it point to the correct bundle depending on the layer
|
||||
// this is because each shared-runtime files are unique per bundle, so if you use app-router context in pages,
|
||||
// it'll be a different instance than the one used in the app-router runtime.
|
||||
if (isSharedRuntime) {
|
||||
if (dev) {
|
||||
return `commonjs ${localRes}`
|
||||
}
|
||||
|
||||
const isNextExternal =
|
||||
/next[/\\]dist[/\\](esm[\\/])?(shared|server)[/\\](?!lib[/\\](router[/\\]router|dynamic|app-dynamic|image-external|lazy-dynamic|head[^-]))/.test(
|
||||
localRes
|
||||
) ||
|
||||
// There's no need to bundle the dev overlay
|
||||
(process.env.NODE_ENV === 'development' &&
|
||||
/next[/\\]dist[/\\](esm[/\\])?client[/\\]components[/\\]react-dev-overlay[/\\]/.test(
|
||||
localRes
|
||||
))
|
||||
const name = path.parse(localRes).name.replace('.shared-runtime', '')
|
||||
|
||||
if (isNextExternal) {
|
||||
// Generate Next.js external import
|
||||
const externalRequest = path.posix.join(
|
||||
'next',
|
||||
'dist',
|
||||
path
|
||||
.relative(
|
||||
// Root of Next.js package:
|
||||
path.join(__dirname, '..'),
|
||||
localRes
|
||||
)
|
||||
// Windows path normalization
|
||||
.replace(/\\/g, '/')
|
||||
const camelCaseName = name.replace(/-([a-z])/g, (_, w) =>
|
||||
w.toUpperCase()
|
||||
)
|
||||
return `commonjs ${externalRequest}`
|
||||
|
||||
// there's no externals for API routes but if need be, they'll need to be added here and have
|
||||
// their own layer
|
||||
const runtime =
|
||||
layer === 'app-route-handler'
|
||||
? 'app-route'
|
||||
: isAppLayer
|
||||
? 'app-page'
|
||||
: 'pages'
|
||||
return [
|
||||
'commonjs ' +
|
||||
path.posix.join(
|
||||
'next',
|
||||
'dist',
|
||||
'compiled',
|
||||
'next-server',
|
||||
`${runtime}.runtime.${dev ? 'dev' : 'prod'}`
|
||||
),
|
||||
'default',
|
||||
'sharedModules',
|
||||
camelCaseName,
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1445,6 +1477,10 @@ export default async function getBaseWebpackConfig(
|
|||
return
|
||||
}
|
||||
|
||||
if (/^next\/dist\/compiled\/next-server/.test(request)) {
|
||||
return `commonjs ${request}`
|
||||
}
|
||||
|
||||
if (
|
||||
/^next\/dist\/shared\/(?!lib\/router\/router)/.test(request) ||
|
||||
/^next\/dist\/compiled\/.*\.c?js$/.test(request)
|
||||
|
@ -2031,6 +2067,14 @@ export default async function getBaseWebpackConfig(
|
|||
},
|
||||
...(hasAppDir
|
||||
? [
|
||||
{
|
||||
layer: WEBPACK_LAYERS.appRouteHandler,
|
||||
test: new RegExp(
|
||||
`private-next-app-dir\\/.*\\/route\\.(${pageExtensions.join(
|
||||
'|'
|
||||
)})$`
|
||||
),
|
||||
},
|
||||
{
|
||||
// Make sure that AsyncLocalStorage module instance is shared between server and client
|
||||
// layers.
|
||||
|
@ -2239,7 +2283,7 @@ export default async function getBaseWebpackConfig(
|
|||
WEBPACK_LAYERS.appPagesBrowser,
|
||||
],
|
||||
},
|
||||
exclude: [asyncStoragesRegex, codeCondition.exclude],
|
||||
exclude: [codeCondition.exclude],
|
||||
use: [
|
||||
...(dev && isClient
|
||||
? [
|
||||
|
|
|
@ -455,7 +455,7 @@ declare module 'next/link' {
|
|||
declare module 'next/navigation' {
|
||||
export * from 'next/dist/client/components/navigation.js'
|
||||
|
||||
import type { NavigateOptions, AppRouterInstance as OriginalAppRouterInstance } from 'next/dist/shared/lib/app-router-context.js'
|
||||
import type { NavigateOptions, AppRouterInstance as OriginalAppRouterInstance } from 'next/dist/shared/lib/app-router-context.shared-runtime.js'
|
||||
interface AppRouterInstance extends OriginalAppRouterInstance {
|
||||
/**
|
||||
* Navigate to the provided href.
|
||||
|
@ -588,8 +588,11 @@ export class NextTypesPlugin {
|
|||
}
|
||||
return
|
||||
}
|
||||
|
||||
if (mod.layer !== WEBPACK_LAYERS.reactServerComponents) return
|
||||
if (
|
||||
mod.layer !== WEBPACK_LAYERS.reactServerComponents &&
|
||||
mod.layer !== WEBPACK_LAYERS.appRouteHandler
|
||||
)
|
||||
return
|
||||
|
||||
const IS_LAYOUT = /[/\\]layout\.[^./\\]+$/.test(mod.resource)
|
||||
const IS_PAGE = !IS_LAYOUT && /[/\\]page\.[^.]+$/.test(mod.resource)
|
||||
|
|
|
@ -7,8 +7,8 @@ import React, { use } from 'react'
|
|||
// eslint-disable-next-line import/no-extraneous-dependencies
|
||||
import { createFromReadableStream } from 'react-server-dom-webpack/client'
|
||||
|
||||
import { HeadManagerContext } from '../shared/lib/head-manager-context'
|
||||
import { GlobalLayoutRouterContext } from '../shared/lib/app-router-context'
|
||||
import { HeadManagerContext } from '../shared/lib/head-manager-context.shared-runtime'
|
||||
import { GlobalLayoutRouterContext } from '../shared/lib/app-router-context.shared-runtime'
|
||||
import onRecoverableError from './on-recoverable-error'
|
||||
import { callServer } from './app-call-server'
|
||||
import { isNextRouterError } from './components/is-next-router-error'
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { useContext } from 'react'
|
||||
import { RouterContext } from '../../shared/lib/router-context'
|
||||
import { RouterContext } from '../../shared/lib/router-context.shared-runtime'
|
||||
import { NextRouter } from '../router'
|
||||
|
||||
/**
|
||||
|
|
|
@ -14,11 +14,11 @@ import {
|
|||
LayoutRouterContext,
|
||||
GlobalLayoutRouterContext,
|
||||
CacheStates,
|
||||
} from '../../shared/lib/app-router-context'
|
||||
} from '../../shared/lib/app-router-context.shared-runtime'
|
||||
import type {
|
||||
CacheNode,
|
||||
AppRouterInstance,
|
||||
} from '../../shared/lib/app-router-context'
|
||||
} from '../../shared/lib/app-router-context.shared-runtime'
|
||||
import type {
|
||||
FlightRouterState,
|
||||
FlightData,
|
||||
|
@ -44,7 +44,7 @@ import { createHrefFromUrl } from './router-reducer/create-href-from-url'
|
|||
import {
|
||||
SearchParamsContext,
|
||||
PathnameContext,
|
||||
} from '../../shared/lib/hooks-client-context'
|
||||
} from '../../shared/lib/hooks-client-context.shared-runtime'
|
||||
import { useReducerWithReduxDevtools } from './use-reducer-with-devtools'
|
||||
import { ErrorBoundary } from './error-boundary'
|
||||
import {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { suspense } from '../../shared/lib/lazy-dynamic/dynamic-no-ssr'
|
||||
import { staticGenerationAsyncStorage } from './static-generation-async-storage'
|
||||
import { staticGenerationAsyncStorage } from './static-generation-async-storage.external'
|
||||
|
||||
export function bailoutToClientRendering(): boolean | never {
|
||||
const staticGenerationStore = staticGenerationAsyncStorage.getStore()
|
||||
|
|
|
@ -4,8 +4,8 @@ import {
|
|||
} from '../../server/web/spec-extension/adapters/request-cookies'
|
||||
import { HeadersAdapter } from '../../server/web/spec-extension/adapters/headers'
|
||||
import { RequestCookies } from '../../server/web/spec-extension/cookies'
|
||||
import { requestAsyncStorage } from './request-async-storage'
|
||||
import { actionAsyncStorage } from './action-async-storage'
|
||||
import { requestAsyncStorage } from './request-async-storage.external'
|
||||
import { actionAsyncStorage } from './action-async-storage.external'
|
||||
import { staticGenerationBailout } from './static-generation-bailout'
|
||||
import { DraftMode } from './draft-mode'
|
||||
|
||||
|
@ -17,7 +17,6 @@ export function headers() {
|
|||
) {
|
||||
return HeadersAdapter.seal(new Headers({}))
|
||||
}
|
||||
|
||||
const requestStore = requestAsyncStorage.getStore()
|
||||
if (!requestStore) {
|
||||
throw new Error(
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
'use client'
|
||||
|
||||
import type { ChildSegmentMap } from '../../shared/lib/app-router-context'
|
||||
import type { ChildSegmentMap } from '../../shared/lib/app-router-context.shared-runtime'
|
||||
import type {
|
||||
FlightRouterState,
|
||||
FlightSegmentPath,
|
||||
|
@ -17,7 +17,7 @@ import {
|
|||
LayoutRouterContext,
|
||||
GlobalLayoutRouterContext,
|
||||
TemplateContext,
|
||||
} from '../../shared/lib/app-router-context'
|
||||
} from '../../shared/lib/app-router-context.shared-runtime'
|
||||
import { fetchServerResponse } from './router-reducer/fetch-server-response'
|
||||
import { createInfinitePromise } from './infinite-promise'
|
||||
import { ErrorBoundary } from './error-boundary'
|
||||
|
|
|
@ -4,11 +4,11 @@ import {
|
|||
AppRouterContext,
|
||||
GlobalLayoutRouterContext,
|
||||
LayoutRouterContext,
|
||||
} from '../../shared/lib/app-router-context'
|
||||
} from '../../shared/lib/app-router-context.shared-runtime'
|
||||
import {
|
||||
SearchParamsContext,
|
||||
PathnameContext,
|
||||
} from '../../shared/lib/hooks-client-context'
|
||||
} from '../../shared/lib/hooks-client-context.shared-runtime'
|
||||
import { clientHookInServerComponentError } from './client-hook-in-server-component-error'
|
||||
import { getSegmentValue } from './router-reducer/reducers/get-segment-value'
|
||||
|
||||
|
@ -111,12 +111,12 @@ export function usePathname(): string {
|
|||
export {
|
||||
ServerInsertedHTMLContext,
|
||||
useServerInsertedHTML,
|
||||
} from '../../shared/lib/server-inserted-html'
|
||||
} from '../../shared/lib/server-inserted-html.shared-runtime'
|
||||
|
||||
/**
|
||||
* Get the router methods. For example router.push('/dashboard')
|
||||
*/
|
||||
export function useRouter(): import('../../shared/lib/app-router-context').AppRouterInstance {
|
||||
export function useRouter(): import('../../shared/lib/app-router-context.shared-runtime').AppRouterInstance {
|
||||
clientHookInServerComponentError('useRouter')
|
||||
const router = useContext(AppRouterContext)
|
||||
if (router === null) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { useCallback, useContext, useEffect, useRef } from 'react'
|
||||
import { GlobalLayoutRouterContext } from '../../../../../shared/lib/app-router-context'
|
||||
import { GlobalLayoutRouterContext } from '../../../../../shared/lib/app-router-context.shared-runtime'
|
||||
import { getSocketUrl } from './get-socket-url'
|
||||
|
||||
export function useWebsocket(assetPrefix: string) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
'use client'
|
||||
import React, { useEffect } from 'react'
|
||||
import { AppRouterInstance } from '../../shared/lib/app-router-context'
|
||||
import { AppRouterInstance } from '../../shared/lib/app-router-context.shared-runtime'
|
||||
import { useRouter } from './navigation'
|
||||
import {
|
||||
RedirectType,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { requestAsyncStorage } from './request-async-storage'
|
||||
import { requestAsyncStorage } from './request-async-storage.external'
|
||||
import type { ResponseCookies } from '../../server/web/spec-extension/cookies'
|
||||
|
||||
const REDIRECT_ERROR_CODE = 'NEXT_REDIRECT'
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
'use client'
|
||||
|
||||
import React, { useContext } from 'react'
|
||||
import { TemplateContext } from '../../shared/lib/app-router-context'
|
||||
import { TemplateContext } from '../../shared/lib/app-router-context.shared-runtime'
|
||||
|
||||
export default function RenderFromTemplateContext(): JSX.Element {
|
||||
const children = useContext(TemplateContext)
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
import { CacheNode, CacheStates } from '../../../shared/lib/app-router-context'
|
||||
import {
|
||||
CacheNode,
|
||||
CacheStates,
|
||||
} from '../../../shared/lib/app-router-context.shared-runtime'
|
||||
import { FlightDataPath } from '../../../server/app-render/types'
|
||||
import { fillLazyItemsTillLeafWithHead } from './fill-lazy-items-till-leaf-with-head'
|
||||
import { fillCacheWithNewSubTreeData } from './fill-cache-with-new-subtree-data'
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
import React from 'react'
|
||||
import type { FlightRouterState } from '../../../server/app-render/types'
|
||||
import { CacheNode, CacheStates } from '../../../shared/lib/app-router-context'
|
||||
import {
|
||||
CacheNode,
|
||||
CacheStates,
|
||||
} from '../../../shared/lib/app-router-context.shared-runtime'
|
||||
import { createInitialRouterState } from './create-initial-router-state'
|
||||
|
||||
const buildId = 'development'
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import type { ReactNode } from 'react'
|
||||
import type { CacheNode } from '../../../shared/lib/app-router-context'
|
||||
import type { CacheNode } from '../../../shared/lib/app-router-context.shared-runtime'
|
||||
import type { FlightRouterState } from '../../../server/app-render/types'
|
||||
|
||||
import { CacheStates } from '../../../shared/lib/app-router-context'
|
||||
import { CacheStates } from '../../../shared/lib/app-router-context.shared-runtime'
|
||||
import { createHrefFromUrl } from './create-href-from-url'
|
||||
import { fillLazyItemsTillLeafWithHead } from './fill-lazy-items-till-leaf-with-head'
|
||||
import { extractPathFromFlightRouterState } from './compute-changed-path'
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
import React from 'react'
|
||||
import { fetchServerResponse } from './fetch-server-response'
|
||||
import { fillCacheWithDataProperty } from './fill-cache-with-data-property'
|
||||
import { CacheStates, CacheNode } from '../../../shared/lib/app-router-context'
|
||||
import {
|
||||
CacheStates,
|
||||
CacheNode,
|
||||
} from '../../../shared/lib/app-router-context.shared-runtime'
|
||||
describe('fillCacheWithDataProperty', () => {
|
||||
it('should add data property', () => {
|
||||
const fetchServerResponseMock: jest.Mock<
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
import { FlightSegmentPath } from '../../../server/app-render/types'
|
||||
import { CacheNode, CacheStates } from '../../../shared/lib/app-router-context'
|
||||
import {
|
||||
CacheNode,
|
||||
CacheStates,
|
||||
} from '../../../shared/lib/app-router-context.shared-runtime'
|
||||
import { createRouterCacheKey } from './create-router-cache-key'
|
||||
import { fetchServerResponse } from './fetch-server-response'
|
||||
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
import React from 'react'
|
||||
import { fillCacheWithNewSubTreeData } from './fill-cache-with-new-subtree-data'
|
||||
import { CacheStates, CacheNode } from '../../../shared/lib/app-router-context'
|
||||
import {
|
||||
CacheStates,
|
||||
CacheNode,
|
||||
} from '../../../shared/lib/app-router-context.shared-runtime'
|
||||
import type { FlightData } from '../../../server/app-render/types'
|
||||
|
||||
const getFlightData = (): FlightData => {
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
import { CacheNode, CacheStates } from '../../../shared/lib/app-router-context'
|
||||
import {
|
||||
CacheNode,
|
||||
CacheStates,
|
||||
} from '../../../shared/lib/app-router-context.shared-runtime'
|
||||
import type { FlightDataPath } from '../../../server/app-render/types'
|
||||
import { invalidateCacheByRouterState } from './invalidate-cache-by-router-state'
|
||||
import { fillLazyItemsTillLeafWithHead } from './fill-lazy-items-till-leaf-with-head'
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
import React from 'react'
|
||||
import { fillLazyItemsTillLeafWithHead } from './fill-lazy-items-till-leaf-with-head'
|
||||
import { CacheStates, CacheNode } from '../../../shared/lib/app-router-context'
|
||||
import {
|
||||
CacheStates,
|
||||
CacheNode,
|
||||
} from '../../../shared/lib/app-router-context.shared-runtime'
|
||||
import type { FlightData } from '../../../server/app-render/types'
|
||||
|
||||
const getFlightData = (): FlightData => {
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
import { CacheNode, CacheStates } from '../../../shared/lib/app-router-context'
|
||||
import {
|
||||
CacheNode,
|
||||
CacheStates,
|
||||
} from '../../../shared/lib/app-router-context.shared-runtime'
|
||||
import type { FlightRouterState } from '../../../server/app-render/types'
|
||||
import { createRouterCacheKey } from './create-router-cache-key'
|
||||
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
import React from 'react'
|
||||
import type { FlightData } from '../../../server/app-render/types'
|
||||
import { invalidateCacheBelowFlightSegmentPath } from './invalidate-cache-below-flight-segmentpath'
|
||||
import { CacheStates, CacheNode } from '../../../shared/lib/app-router-context'
|
||||
import {
|
||||
CacheStates,
|
||||
CacheNode,
|
||||
} from '../../../shared/lib/app-router-context.shared-runtime'
|
||||
import { fillCacheWithNewSubTreeData } from './fill-cache-with-new-subtree-data'
|
||||
|
||||
const getFlightData = (): FlightData => {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import type { CacheNode } from '../../../shared/lib/app-router-context'
|
||||
import type { CacheNode } from '../../../shared/lib/app-router-context.shared-runtime'
|
||||
import type { FlightSegmentPath } from '../../../server/app-render/types'
|
||||
import { createRouterCacheKey } from './create-router-cache-key'
|
||||
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
import React from 'react'
|
||||
import { invalidateCacheByRouterState } from './invalidate-cache-by-router-state'
|
||||
import { CacheStates, CacheNode } from '../../../shared/lib/app-router-context'
|
||||
import {
|
||||
CacheStates,
|
||||
CacheNode,
|
||||
} from '../../../shared/lib/app-router-context.shared-runtime'
|
||||
import type { FlightRouterState } from '../../../server/app-render/types'
|
||||
|
||||
describe('invalidateCacheByRouterState', () => {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import type { CacheNode } from '../../../shared/lib/app-router-context'
|
||||
import type { CacheNode } from '../../../shared/lib/app-router-context.shared-runtime'
|
||||
import type { FlightRouterState } from '../../../server/app-render/types'
|
||||
import { createRouterCacheKey } from './create-router-cache-key'
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ import type { FlightRouterState } from '../../../../server/app-render/types'
|
|||
import {
|
||||
CacheNode,
|
||||
CacheStates,
|
||||
} from '../../../../shared/lib/app-router-context'
|
||||
} from '../../../../shared/lib/app-router-context.shared-runtime'
|
||||
import { findHeadInCache } from './find-head-in-cache'
|
||||
|
||||
describe('findHeadInCache', () => {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import type { FlightRouterState } from '../../../../server/app-render/types'
|
||||
import type { CacheNode } from '../../../../shared/lib/app-router-context'
|
||||
import type { CacheNode } from '../../../../shared/lib/app-router-context.shared-runtime'
|
||||
import { createRouterCacheKey } from '../create-router-cache-key'
|
||||
|
||||
export function findHeadInCache(
|
||||
|
|
|
@ -79,7 +79,7 @@ import { FlightRouterState } from '../../../../server/app-render/types'
|
|||
import {
|
||||
CacheNode,
|
||||
CacheStates,
|
||||
} from '../../../../shared/lib/app-router-context'
|
||||
} from '../../../../shared/lib/app-router-context.shared-runtime'
|
||||
import { createInitialRouterState } from '../create-initial-router-state'
|
||||
import {
|
||||
NavigateAction,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import {
|
||||
CacheNode,
|
||||
CacheStates,
|
||||
} from '../../../../shared/lib/app-router-context'
|
||||
} from '../../../../shared/lib/app-router-context.shared-runtime'
|
||||
import type {
|
||||
FlightRouterState,
|
||||
FlightSegmentPath,
|
||||
|
|
|
@ -36,7 +36,7 @@ import { FlightRouterState } from '../../../../server/app-render/types'
|
|||
import {
|
||||
CacheNode,
|
||||
CacheStates,
|
||||
} from '../../../../shared/lib/app-router-context'
|
||||
} from '../../../../shared/lib/app-router-context.shared-runtime'
|
||||
import { createInitialRouterState } from '../create-initial-router-state'
|
||||
import {
|
||||
PrefetchAction,
|
||||
|
|
|
@ -46,7 +46,7 @@ import { FlightRouterState } from '../../../../server/app-render/types'
|
|||
import {
|
||||
CacheNode,
|
||||
CacheStates,
|
||||
} from '../../../../shared/lib/app-router-context'
|
||||
} from '../../../../shared/lib/app-router-context.shared-runtime'
|
||||
import { createInitialRouterState } from '../create-initial-router-state'
|
||||
import { RefreshAction, ACTION_REFRESH } from '../router-reducer-types'
|
||||
import { refreshReducer } from './refresh-reducer'
|
||||
|
|
|
@ -11,7 +11,7 @@ import {
|
|||
} from '../router-reducer-types'
|
||||
import { handleExternalUrl } from './navigate-reducer'
|
||||
import { handleMutable } from '../handle-mutable'
|
||||
import { CacheStates } from '../../../../shared/lib/app-router-context'
|
||||
import { CacheStates } from '../../../../shared/lib/app-router-context.shared-runtime'
|
||||
import { fillLazyItemsTillLeafWithHead } from '../fill-lazy-items-till-leaf-with-head'
|
||||
|
||||
export function refreshReducer(
|
||||
|
|
|
@ -3,7 +3,7 @@ import type { FlightRouterState } from '../../../../server/app-render/types'
|
|||
import {
|
||||
CacheNode,
|
||||
CacheStates,
|
||||
} from '../../../../shared/lib/app-router-context'
|
||||
} from '../../../../shared/lib/app-router-context.shared-runtime'
|
||||
import { createInitialRouterState } from '../create-initial-router-state'
|
||||
import { RestoreAction, ACTION_RESTORE } from '../router-reducer-types'
|
||||
import { restoreReducer } from './restore-reducer'
|
||||
|
|
|
@ -27,7 +27,7 @@ import { createHrefFromUrl } from '../create-href-from-url'
|
|||
import { handleExternalUrl } from './navigate-reducer'
|
||||
import { applyRouterStatePatchToTree } from '../apply-router-state-patch-to-tree'
|
||||
import { isNavigatingToNewRootLayout } from '../is-navigating-to-new-root-layout'
|
||||
import { CacheStates } from '../../../../shared/lib/app-router-context'
|
||||
import { CacheStates } from '../../../../shared/lib/app-router-context.shared-runtime'
|
||||
import { handleMutable } from '../handle-mutable'
|
||||
import { fillLazyItemsTillLeafWithHead } from '../fill-lazy-items-till-leaf-with-head'
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ jest.mock('../fetch-server-response', () => {
|
|||
import {
|
||||
CacheNode,
|
||||
CacheStates,
|
||||
} from '../../../../shared/lib/app-router-context'
|
||||
} from '../../../../shared/lib/app-router-context.shared-runtime'
|
||||
import { createInitialRouterState } from '../create-initial-router-state'
|
||||
import {
|
||||
ServerPatchAction,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import type { CacheNode } from '../../../shared/lib/app-router-context'
|
||||
import type { CacheNode } from '../../../shared/lib/app-router-context.shared-runtime'
|
||||
import type {
|
||||
FlightRouterState,
|
||||
FlightData,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { DynamicServerError } from './hooks-server-context'
|
||||
import { staticGenerationAsyncStorage } from './static-generation-async-storage'
|
||||
import { staticGenerationAsyncStorage } from './static-generation-async-storage.external'
|
||||
|
||||
class StaticGenBailoutError extends Error {
|
||||
code = 'NEXT_STATIC_GEN_BAILOUT'
|
||||
|
|
|
@ -25,9 +25,9 @@ import type {
|
|||
ImageLoaderProps,
|
||||
} from '../shared/lib/image-config'
|
||||
import { imageConfigDefault } from '../shared/lib/image-config'
|
||||
import { ImageConfigContext } from '../shared/lib/image-config-context'
|
||||
import { ImageConfigContext } from '../shared/lib/image-config-context.shared-runtime'
|
||||
import { warnOnce } from '../shared/lib/utils/warn-once'
|
||||
import { RouterContext } from '../shared/lib/router-context'
|
||||
import { RouterContext } from '../shared/lib/router-context.shared-runtime'
|
||||
|
||||
// @ts-ignore - This is replaced by webpack alias
|
||||
import defaultLoader from 'next/dist/shared/lib/image-loader'
|
||||
|
|
|
@ -10,16 +10,16 @@ import type {
|
|||
|
||||
import React from 'react'
|
||||
import ReactDOM from 'react-dom/client'
|
||||
import { HeadManagerContext } from '../shared/lib/head-manager-context'
|
||||
import { HeadManagerContext } from '../shared/lib/head-manager-context.shared-runtime'
|
||||
import mitt, { MittEmitter } from '../shared/lib/mitt'
|
||||
import { RouterContext } from '../shared/lib/router-context'
|
||||
import { RouterContext } from '../shared/lib/router-context.shared-runtime'
|
||||
import { handleSmoothScroll } from '../shared/lib/router/utils/handle-smooth-scroll'
|
||||
import { isDynamicRoute } from '../shared/lib/router/utils/is-dynamic'
|
||||
import {
|
||||
urlQueryToSearchParams,
|
||||
assign,
|
||||
} from '../shared/lib/router/utils/querystring'
|
||||
import { setConfig } from '../shared/lib/runtime-config'
|
||||
import { setConfig } from '../shared/lib/runtime-config.shared-runtime'
|
||||
import {
|
||||
getURL,
|
||||
loadGetInitialProps,
|
||||
|
@ -34,17 +34,17 @@ import measureWebVitals from './performance-relayer'
|
|||
import { RouteAnnouncer } from './route-announcer'
|
||||
import { createRouter, makePublicRouterInstance } from './router'
|
||||
import { getProperError } from '../lib/is-error'
|
||||
import { ImageConfigContext } from '../shared/lib/image-config-context'
|
||||
import { ImageConfigContext } from '../shared/lib/image-config-context.shared-runtime'
|
||||
import { ImageConfigComplete } from '../shared/lib/image-config'
|
||||
import { removeBasePath } from './remove-base-path'
|
||||
import { hasBasePath } from './has-base-path'
|
||||
import { AppRouterContext } from '../shared/lib/app-router-context'
|
||||
import { AppRouterContext } from '../shared/lib/app-router-context.shared-runtime'
|
||||
import {
|
||||
adaptForAppRouterInstance,
|
||||
adaptForSearchParams,
|
||||
PathnameContextProviderAdapter,
|
||||
} from '../shared/lib/router/adapters'
|
||||
import { SearchParamsContext } from '../shared/lib/hooks-client-context'
|
||||
} from '../shared/lib/router/adapters.shared-runtime'
|
||||
import { SearchParamsContext } from '../shared/lib/hooks-client-context.shared-runtime'
|
||||
import onRecoverableError from './on-recoverable-error'
|
||||
import tracer from './tracing/tracer'
|
||||
import reportToSocket from './tracing/report-to-socket'
|
||||
|
|
|
@ -16,7 +16,7 @@ import {
|
|||
VALID_LOADERS,
|
||||
} from '../../shared/lib/image-config'
|
||||
import { useIntersection } from '../use-intersection'
|
||||
import { ImageConfigContext } from '../../shared/lib/image-config-context'
|
||||
import { ImageConfigContext } from '../../shared/lib/image-config-context.shared-runtime'
|
||||
import { warnOnce } from '../../shared/lib/utils/warn-once'
|
||||
import { normalizePathTrailingSlash } from '../normalize-trailing-slash'
|
||||
|
||||
|
|
|
@ -12,12 +12,12 @@ import { isLocalURL } from '../shared/lib/router/utils/is-local-url'
|
|||
import { formatUrl } from '../shared/lib/router/utils/format-url'
|
||||
import { isAbsoluteUrl } from '../shared/lib/utils'
|
||||
import { addLocale } from './add-locale'
|
||||
import { RouterContext } from '../shared/lib/router-context'
|
||||
import { RouterContext } from '../shared/lib/router-context.shared-runtime'
|
||||
import {
|
||||
AppRouterContext,
|
||||
AppRouterInstance,
|
||||
PrefetchOptions as AppRouterPrefetchOptions,
|
||||
} from '../shared/lib/app-router-context'
|
||||
} from '../shared/lib/app-router-context.shared-runtime'
|
||||
import { useIntersection } from './use-intersection'
|
||||
import { getDomainLocale } from './get-domain-locale'
|
||||
import { addBasePath } from './add-base-path'
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
import React from 'react'
|
||||
import Router from '../shared/lib/router/router'
|
||||
import type { NextRouter } from '../shared/lib/router/router'
|
||||
import { RouterContext } from '../shared/lib/router-context'
|
||||
import { RouterContext } from '../shared/lib/router-context.shared-runtime'
|
||||
import isError from '../lib/is-error'
|
||||
|
||||
type SingletonRouterBase = {
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
import ReactDOM from 'react-dom'
|
||||
import React, { useEffect, useContext, useRef } from 'react'
|
||||
import { ScriptHTMLAttributes } from 'react'
|
||||
import { HeadManagerContext } from '../shared/lib/head-manager-context'
|
||||
import { HeadManagerContext } from '../shared/lib/head-manager-context.shared-runtime'
|
||||
import { DOMAttributeNames } from './head-manager'
|
||||
import { requestIdleCallback } from './request-idle-callback'
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ import {
|
|||
RSC,
|
||||
} from '../client/components/app-router-headers'
|
||||
|
||||
const envConfig = require('../shared/lib/runtime-config')
|
||||
const envConfig = require('../shared/lib/runtime-config.shared-runtime')
|
||||
|
||||
;(globalThis as any).__NEXT_DATA__ = {
|
||||
nextExport: true,
|
||||
|
@ -307,8 +307,10 @@ export default async function exportPage({
|
|||
await promises.mkdir(baseDir, { recursive: true })
|
||||
let renderResult: RenderResult | undefined
|
||||
let curRenderOpts: RenderOpts = {}
|
||||
const { renderToHTML } =
|
||||
require('../server/render') as typeof import('../server/render')
|
||||
const renderToHTML =
|
||||
require('../server/future/route-modules/pages/module.compiled')
|
||||
.renderToHTML as typeof import('../server/render').renderToHTML
|
||||
|
||||
let renderMethod = renderToHTML
|
||||
let inAmpMode = false,
|
||||
hybridAmp = false
|
||||
|
@ -479,7 +481,6 @@ export default async function exportPage({
|
|||
const module = await RouteModuleLoader.load<AppRouteRouteModule>(
|
||||
filename
|
||||
)
|
||||
|
||||
// Call the handler with the request and context from the module.
|
||||
const response = await module.handle(request, context)
|
||||
|
||||
|
@ -535,8 +536,9 @@ export default async function exportPage({
|
|||
results.fromBuildExportRevalidate = 0
|
||||
}
|
||||
} else {
|
||||
const { renderToHTMLOrFlight } =
|
||||
require('../server/app-render/app-render') as typeof import('../server/app-render/app-render')
|
||||
const renderToHTMLOrFlight =
|
||||
require('../server/future/route-modules/app-page/module.compiled')
|
||||
.renderToHTMLOrFlight as typeof import('../server/app-render/app-render').renderToHTMLOrFlight
|
||||
|
||||
try {
|
||||
curRenderOpts.params ||= {}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
let chalk: typeof import('next/dist/compiled/chalk')
|
||||
|
||||
if (process.env.NEXT_RUNTIME === 'edge') {
|
||||
if (process.env.NEXT_RUNTIME === 'edge' || process.env.NEXT_MINIMAL) {
|
||||
chalk = require('./web/chalk').default
|
||||
} else {
|
||||
chalk = require('next/dist/compiled/chalk')
|
||||
|
|
|
@ -132,6 +132,10 @@ const WEBPACK_LAYERS_NAMES = {
|
|||
* The server bundle layer for metadata routes.
|
||||
*/
|
||||
appMetadataRoute: 'app-metadata-route',
|
||||
/**
|
||||
* The layer for the server bundle for App Route handlers.
|
||||
*/
|
||||
appRouteHandler: 'app-route-handler',
|
||||
}
|
||||
|
||||
export const WEBPACK_LAYERS = {
|
||||
|
@ -141,6 +145,7 @@ export const WEBPACK_LAYERS = {
|
|||
WEBPACK_LAYERS_NAMES.reactServerComponents,
|
||||
WEBPACK_LAYERS_NAMES.actionBrowser,
|
||||
WEBPACK_LAYERS_NAMES.appMetadataRoute,
|
||||
WEBPACK_LAYERS_NAMES.appRouteHandler,
|
||||
],
|
||||
},
|
||||
}
|
||||
|
|
|
@ -17,8 +17,11 @@ import { BuildManifest, getPageFiles } from '../server/get-page-files'
|
|||
import { htmlEscapeJsonString } from '../server/htmlescape'
|
||||
import isError from '../lib/is-error'
|
||||
|
||||
import { HtmlContext, useHtmlContext } from '../shared/lib/html-context'
|
||||
import type { HtmlProps } from '../shared/lib/html-context'
|
||||
import {
|
||||
HtmlContext,
|
||||
useHtmlContext,
|
||||
} from '../shared/lib/html-context.shared-runtime'
|
||||
import type { HtmlProps } from '../shared/lib/html-context.shared-runtime'
|
||||
|
||||
export { DocumentContext, DocumentInitialProps, DocumentProps }
|
||||
|
||||
|
|
|
@ -19,10 +19,10 @@ import {
|
|||
isRedirectError,
|
||||
} from '../../client/components/redirect'
|
||||
import RenderResult from '../render-result'
|
||||
import { StaticGenerationStore } from '../../client/components/static-generation-async-storage'
|
||||
import { StaticGenerationStore } from '../../client/components/static-generation-async-storage.external'
|
||||
import { FlightRenderResult } from './flight-render-result'
|
||||
import { ActionResult } from './types'
|
||||
import { ActionAsyncStorage } from '../../client/components/action-async-storage'
|
||||
import { ActionAsyncStorage } from '../../client/components/action-async-storage.external'
|
||||
import {
|
||||
filterReqHeaders,
|
||||
actionsForbiddenHeaders,
|
||||
|
@ -31,7 +31,8 @@ import {
|
|||
appendMutableCookies,
|
||||
getModifiedCookieValues,
|
||||
} from '../web/spec-extension/adapters/request-cookies'
|
||||
import { RequestStore } from '../../client/components/request-async-storage'
|
||||
|
||||
import { RequestStore } from '../../client/components/request-async-storage.external'
|
||||
import {
|
||||
NEXT_CACHE_REVALIDATED_TAGS_HEADER,
|
||||
NEXT_CACHE_REVALIDATE_TAG_TOKEN_HEADER,
|
||||
|
|
|
@ -11,9 +11,9 @@ import type {
|
|||
Segment,
|
||||
} from './types'
|
||||
|
||||
import type { StaticGenerationAsyncStorage } from '../../client/components/static-generation-async-storage'
|
||||
import type { StaticGenerationAsyncStorage } from '../../client/components/static-generation-async-storage.external'
|
||||
import type { StaticGenerationBailout } from '../../client/components/static-generation-bailout'
|
||||
import type { RequestAsyncStorage } from '../../client/components/request-async-storage'
|
||||
import type { RequestAsyncStorage } from '../../client/components/request-async-storage.external'
|
||||
|
||||
import React from 'react'
|
||||
import { createServerComponentRenderer } from './create-server-components-renderer'
|
||||
|
@ -286,10 +286,13 @@ export async function renderToHTMLOrFlight(
|
|||
* that we need to resolve the final metadata.
|
||||
*/
|
||||
|
||||
const requestId =
|
||||
process.env.NEXT_RUNTIME === 'edge'
|
||||
? crypto.randomUUID()
|
||||
: require('next/dist/compiled/nanoid').nanoid()
|
||||
let requestId: string
|
||||
|
||||
if (process.env.NEXT_RUNTIME === 'edge') {
|
||||
requestId = crypto.randomUUID()
|
||||
} else {
|
||||
requestId = require('next/dist/compiled/nanoid').nanoid()
|
||||
}
|
||||
|
||||
const LayoutRouter =
|
||||
ComponentMod.LayoutRouter as typeof import('../../client/components/layout-router').default
|
||||
|
@ -1392,7 +1395,7 @@ export async function renderToHTMLOrFlight(
|
|||
)
|
||||
|
||||
const { HeadManagerContext } =
|
||||
require('../../shared/lib/head-manager-context') as typeof import('../../shared/lib/head-manager-context')
|
||||
require('../../shared/lib/head-manager-context.shared-runtime') as typeof import('../../shared/lib/head-manager-context.shared-runtime')
|
||||
|
||||
// On each render, create a new `ServerInsertedHTML` context to capture
|
||||
// injected nodes from user code (`useServerInsertedHTML`).
|
||||
|
|
|
@ -1,36 +1,26 @@
|
|||
const { default: AppRouter } =
|
||||
require('next/dist/client/components/app-router') as typeof import('../../client/components/app-router')
|
||||
const { default: LayoutRouter } =
|
||||
require('next/dist/client/components/layout-router') as typeof import('../../client/components/layout-router')
|
||||
const { default: RenderFromTemplateContext } =
|
||||
require('next/dist/client/components/render-from-template-context') as typeof import('../../client/components/render-from-template-context')
|
||||
|
||||
const { staticGenerationAsyncStorage } =
|
||||
require('next/dist/client/components/static-generation-async-storage') as typeof import('../../client/components/static-generation-async-storage')
|
||||
|
||||
const { requestAsyncStorage } =
|
||||
require('next/dist/client/components/request-async-storage') as typeof import('../../client/components/request-async-storage')
|
||||
const { actionAsyncStorage } =
|
||||
require('next/dist/client/components/action-async-storage') as typeof import('../../client/components/action-async-storage')
|
||||
|
||||
const { staticGenerationBailout } =
|
||||
require('next/dist/client/components/static-generation-bailout') as typeof import('../../client/components/static-generation-bailout')
|
||||
const { default: StaticGenerationSearchParamsBailoutProvider } =
|
||||
require('next/dist/client/components/static-generation-searchparams-bailout-provider') as typeof import('../../client/components/static-generation-searchparams-bailout-provider')
|
||||
const { createSearchParamsBailoutProxy } =
|
||||
require('next/dist/client/components/searchparams-bailout-proxy') as typeof import('../../client/components/searchparams-bailout-proxy')
|
||||
|
||||
const serverHooks =
|
||||
require('next/dist/client/components/hooks-server-context') as typeof import('../../client/components/hooks-server-context')
|
||||
|
||||
const {
|
||||
renderToReadableStream,
|
||||
decodeReply,
|
||||
decodeAction,
|
||||
// eslint-disable-next-line import/no-extraneous-dependencies
|
||||
} = require('react-server-dom-webpack/server.edge')
|
||||
const { preloadStyle, preloadFont, preconnect } =
|
||||
require('next/dist/server/app-render/rsc/preloads') as typeof import('../../server/app-render/rsc/preloads')
|
||||
|
||||
import AppRouter from '../../client/components/app-router'
|
||||
import LayoutRouter from '../../client/components/layout-router'
|
||||
import RenderFromTemplateContext from '../../client/components/render-from-template-context'
|
||||
import { staticGenerationAsyncStorage } from '../../client/components/static-generation-async-storage.external'
|
||||
import { requestAsyncStorage } from '../../client/components/request-async-storage.external'
|
||||
import { actionAsyncStorage } from '../../client/components/action-async-storage.external'
|
||||
import { staticGenerationBailout } from '../../client/components/static-generation-bailout'
|
||||
import StaticGenerationSearchParamsBailoutProvider from '../../client/components/static-generation-searchparams-bailout-provider'
|
||||
import { createSearchParamsBailoutProxy } from '../../client/components/searchparams-bailout-proxy'
|
||||
import * as serverHooks from '../../client/components/hooks-server-context'
|
||||
|
||||
import {
|
||||
preloadStyle,
|
||||
preloadFont,
|
||||
preconnect,
|
||||
} from '../../server/app-render/rsc/preloads'
|
||||
|
||||
const { NotFoundBoundary } =
|
||||
require('next/dist/client/components/not-found-boundary') as typeof import('../../client/components/not-found-boundary')
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// elements into the HTML stream.
|
||||
|
||||
import React from 'react'
|
||||
import { ServerInsertedHTMLContext } from '../../shared/lib/server-inserted-html'
|
||||
import { ServerInsertedHTMLContext } from '../../shared/lib/server-inserted-html.shared-runtime'
|
||||
|
||||
export function createServerInsertedHTML() {
|
||||
const serverInsertedHTMLCallbacks: (() => React.ReactNode)[] = []
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import type { BaseNextRequest, BaseNextResponse } from '../base-http'
|
||||
import type { IncomingHttpHeaders, IncomingMessage, ServerResponse } from 'http'
|
||||
import type { AsyncLocalStorage } from 'async_hooks'
|
||||
import type { RequestStore } from '../../client/components/request-async-storage'
|
||||
import type { RequestStore } from '../../client/components/request-async-storage.external'
|
||||
import type { RenderOpts } from '../app-render/types'
|
||||
import type { AsyncStorageWrapper } from './async-storage-wrapper'
|
||||
import type { NextRequest } from '../web/spec-extension/request'
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import type { AsyncStorageWrapper } from './async-storage-wrapper'
|
||||
import type { StaticGenerationStore } from '../../client/components/static-generation-async-storage'
|
||||
import type { StaticGenerationStore } from '../../client/components/static-generation-async-storage.external'
|
||||
import type { AsyncLocalStorage } from 'async_hooks'
|
||||
import type { IncrementalCache } from '../lib/incremental-cache'
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ import {
|
|||
getCookieParser,
|
||||
checkIsOnDemandRevalidate,
|
||||
} from './api-utils'
|
||||
import { setConfig } from '../shared/lib/runtime-config'
|
||||
import { setConfig } from '../shared/lib/runtime-config.shared-runtime'
|
||||
|
||||
import { setRevalidateHeaders } from './send-payload/revalidate-headers'
|
||||
import { execOnce } from '../shared/lib/utils'
|
||||
|
@ -428,7 +428,11 @@ export default abstract class Server<ServerOptions extends Options = Options> {
|
|||
} = this.nextConfig
|
||||
|
||||
this.buildId = this.getBuildId()
|
||||
this.minimalMode = minimalMode || !!process.env.NEXT_PRIVATE_MINIMAL_MODE
|
||||
// this is a hack to avoid Webpack knowing this is equal to this.minimalMode
|
||||
// because we replace this.minimalMode to true in production bundles.
|
||||
const minimalModeKey = 'minimalMode'
|
||||
this[minimalModeKey] =
|
||||
minimalMode || !!process.env.NEXT_PRIVATE_MINIMAL_MODE
|
||||
|
||||
this.hasAppDir = this.getHasAppDir(dev)
|
||||
const serverComponents = this.hasAppDir
|
||||
|
|
|
@ -41,7 +41,7 @@ import {
|
|||
UnwrapPromise,
|
||||
withCoalescedInvoke,
|
||||
} from '../../lib/coalesced-function'
|
||||
import { loadDefaultErrorComponents } from '../load-components'
|
||||
import { loadDefaultErrorComponents } from '../load-default-error-components'
|
||||
import { DecodeError, MiddlewareNotFoundError } from '../../shared/lib/utils'
|
||||
import * as Log from '../../build/output/log'
|
||||
import isError, { getProperError } from '../../lib/is-error'
|
||||
|
|
|
@ -14,8 +14,10 @@ import { loadComponents } from '../load-components'
|
|||
import { setHttpClientAndAgentOptions } from '../setup-http-agent-env'
|
||||
import { IncrementalCache } from '../lib/incremental-cache'
|
||||
import * as serverHooks from '../../client/components/hooks-server-context'
|
||||
import { staticGenerationAsyncStorage } from '../../client/components/static-generation-async-storage'
|
||||
import { AppRouteRouteModule } from '../future/route-modules/app-route/module'
|
||||
import { staticGenerationAsyncStorage } from '../../client/components/static-generation-async-storage.external'
|
||||
|
||||
const { AppRouteRouteModule } =
|
||||
require('../future/route-modules/app-route/module.compiled') as typeof import('../future/route-modules/app-route/module')
|
||||
|
||||
type RuntimeConfig = any
|
||||
|
||||
|
@ -56,7 +58,7 @@ export async function loadStaticPaths({
|
|||
fallback?: boolean | 'blocking'
|
||||
}> {
|
||||
// update work memory runtime-config
|
||||
require('../../shared/lib/runtime-config').setConfig(config)
|
||||
require('../../shared/lib/runtime-config.shared-runtime').setConfig(config)
|
||||
setHttpClientAndAgentOptions({
|
||||
httpAgentOptions,
|
||||
})
|
||||
|
|
|
@ -7,7 +7,10 @@ export class NodeModuleLoader implements ModuleLoader {
|
|||
public async load<M>(id: string): Promise<M> {
|
||||
if (process.env.NEXT_RUNTIME !== 'edge') {
|
||||
// Need to `await` to cover the case that route is marked ESM modules by ESM escalation.
|
||||
return await require(id)
|
||||
return await (process.env.NEXT_MINIMAL
|
||||
? // @ts-ignore
|
||||
__non_webpack_require__(id)
|
||||
: require(id))
|
||||
}
|
||||
|
||||
throw new Error('NodeModuleLoader is not supported in edge runtime.')
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
if (process.env.NEXT_RUNTIME === 'edge') {
|
||||
module.exports = require('next/dist/server/future/route-modules/app-page/module.js')
|
||||
} else {
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
module.exports = require('next/dist/compiled/next-server/app-page.runtime.dev.js')
|
||||
} else if (process.env.TURBOPACK) {
|
||||
module.exports = require('next/dist/compiled/next-server/app-page-turbo.runtime.prod.js')
|
||||
} else {
|
||||
module.exports = require('next/dist/compiled/next-server/app-page.runtime.prod.js')
|
||||
}
|
||||
}
|
|
@ -11,6 +11,7 @@ import {
|
|||
type RouteModuleOptions,
|
||||
type RouteModuleHandleContext,
|
||||
} from '../route-module'
|
||||
import * as sharedModules from './shared-modules'
|
||||
|
||||
type AppPageUserlandModule = {
|
||||
/**
|
||||
|
@ -34,6 +35,8 @@ export class AppPageRouteModule extends RouteModule<
|
|||
AppPageRouteDefinition,
|
||||
AppPageUserlandModule
|
||||
> {
|
||||
static readonly sharedModules = sharedModules
|
||||
|
||||
public render(
|
||||
req: IncomingMessage,
|
||||
res: ServerResponse,
|
||||
|
@ -49,4 +52,6 @@ export class AppPageRouteModule extends RouteModule<
|
|||
}
|
||||
}
|
||||
|
||||
export { renderToHTMLOrFlight }
|
||||
|
||||
export default AppPageRouteModule
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
// the name of the export has to be the camelCase version of the file name (without the extension)
|
||||
export * as headManagerContext from '../../../../shared/lib/head-manager-context.shared-runtime'
|
||||
export * as serverInsertedHtml from '../../../../shared/lib/server-inserted-html.shared-runtime'
|
||||
export * as appRouterContext from '../../../../shared/lib/app-router-context.shared-runtime'
|
||||
export * as hooksClientContext from '../../../../shared/lib/hooks-client-context.shared-runtime'
|
||||
export * as routerContext from '../../../../shared/lib/router-context.shared-runtime'
|
||||
export * as htmlContext from '../../../../shared/lib/html-context.shared-runtime'
|
||||
export * as ampContext from '../../../../shared/lib/amp-context.shared-runtime'
|
||||
export * as adapters from '../../../../shared/lib/router/adapters.shared-runtime'
|
||||
export * as loadableContext from '../../../../shared/lib/loadable-context.shared-runtime'
|
||||
export * as imageConfigContext from '../../../../shared/lib/image-config-context.shared-runtime'
|
||||
export * as runtimeConfig from '../../../../shared/lib/runtime-config.shared-runtime'
|
||||
export * as loadable from '../../../../shared/lib/loadable.shared-runtime'
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue