Skip to content

Commit ac62406

Browse files
authored
Revert "Separate routing code from render servers (#52492)" (#53016)
Temporarily reverts these changes to allow patch release first. Reverts: #52149 Reverts: #52492
1 parent 1fefb4a commit ac62406

File tree

68 files changed

+4857
-5820
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+4857
-5820
lines changed

packages/next-swc/crates/next-build/src/next_pages/page_entries.rs

+4-142
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
use std::io::Write;
2-
31
use anyhow::{bail, Result};
4-
use indexmap::indexmap;
5-
use indoc::writedoc;
62
use next_core::{
73
create_page_loader_entry_module, get_asset_path_from_pathname,
84
mode::NextMode,
@@ -24,23 +20,17 @@ use next_core::{
2420
};
2521
use turbo_tasks::Vc;
2622
use turbopack_binding::{
27-
turbo::{
28-
tasks::Value,
29-
tasks_env::ProcessEnv,
30-
tasks_fs::{rope::RopeBuilder, File, FileSystemPath},
31-
},
23+
turbo::{tasks::Value, tasks_env::ProcessEnv, tasks_fs::FileSystemPath},
3224
turbopack::{
3325
build::BuildChunkingContext,
3426
core::{
35-
asset::AssetContent,
3627
chunk::{ChunkableModule, ChunkingContext, EvaluatableAssets},
3728
compile_time_info::CompileTimeInfo,
3829
context::AssetContext,
3930
file_source::FileSource,
4031
output::OutputAsset,
4132
reference_type::{EntryReferenceSubType, ReferenceType},
4233
source::Source,
43-
virtual_source::VirtualSource,
4434
},
4535
ecmascript::{
4636
chunk::{EcmascriptChunkPlaceable, EcmascriptChunkingContext},
@@ -201,8 +191,6 @@ async fn get_page_entries_for_root_directory(
201191
Vc::upcast(FileSource::new(app.project_path)),
202192
next_router_root,
203193
app.next_router_path,
204-
app.original_path,
205-
PathType::Page,
206194
));
207195

208196
// This only makes sense on the server.
@@ -213,8 +201,6 @@ async fn get_page_entries_for_root_directory(
213201
Vc::upcast(FileSource::new(document.project_path)),
214202
next_router_root,
215203
document.next_router_path,
216-
document.original_path,
217-
PathType::Page,
218204
));
219205

220206
// This only makes sense on both the client and the server, but they should map
@@ -226,8 +212,6 @@ async fn get_page_entries_for_root_directory(
226212
Vc::upcast(FileSource::new(error.project_path)),
227213
next_router_root,
228214
error.next_router_path,
229-
error.original_path,
230-
PathType::Page,
231215
));
232216

233217
if let Some(api) = api {
@@ -237,7 +221,6 @@ async fn get_page_entries_for_root_directory(
237221
api,
238222
next_router_root,
239223
&mut entries,
240-
PathType::PagesAPI,
241224
)
242225
.await?;
243226
}
@@ -249,7 +232,6 @@ async fn get_page_entries_for_root_directory(
249232
pages,
250233
next_router_root,
251234
&mut entries,
252-
PathType::Page,
253235
)
254236
.await?;
255237
}
@@ -264,7 +246,6 @@ async fn get_page_entries_for_directory(
264246
pages_structure: Vc<PagesDirectoryStructure>,
265247
next_router_root: Vc<FileSystemPath>,
266248
entries: &mut Vec<Vc<PageEntry>>,
267-
path_type: PathType,
268249
) -> Result<()> {
269250
let PagesDirectoryStructure {
270251
ref items,
@@ -276,16 +257,14 @@ async fn get_page_entries_for_directory(
276257
let PagesStructureItem {
277258
project_path,
278259
next_router_path,
279-
original_path,
260+
original_path: _,
280261
} = *item.await?;
281262
entries.push(get_page_entry_for_file(
282263
ssr_module_context,
283264
client_module_context,
284265
Vc::upcast(FileSource::new(project_path)),
285266
next_router_root,
286267
next_router_path,
287-
original_path,
288-
path_type,
289268
));
290269
}
291270

@@ -296,7 +275,6 @@ async fn get_page_entries_for_directory(
296275
*child,
297276
next_router_root,
298277
entries,
299-
path_type,
300278
)
301279
.await?;
302280
}
@@ -322,129 +300,13 @@ async fn get_page_entry_for_file(
322300
source: Vc<Box<dyn Source>>,
323301
next_router_root: Vc<FileSystemPath>,
324302
next_router_path: Vc<FileSystemPath>,
325-
next_original_path: Vc<FileSystemPath>,
326-
path_type: PathType,
327303
) -> Result<Vc<PageEntry>> {
328-
let reference_type = Value::new(ReferenceType::Entry(match path_type {
329-
PathType::Page => EntryReferenceSubType::Page,
330-
PathType::PagesAPI => EntryReferenceSubType::PagesApi,
331-
_ => bail!("Invalid path type"),
332-
}));
333-
334-
let pathname = pathname_for_path(next_router_root, next_router_path, path_type);
304+
let reference_type = Value::new(ReferenceType::Entry(EntryReferenceSubType::Page));
335305

336-
let definition_page = format!("/{}", next_original_path.await?);
337-
let definition_pathname = pathname.await?;
306+
let pathname = pathname_for_path(next_router_root, next_router_path, PathType::Page);
338307

339308
let ssr_module = ssr_module_context.process(source, reference_type.clone());
340309

341-
let mut result = RopeBuilder::default();
342-
343-
match path_type {
344-
PathType::Page => {
345-
// Sourced from https://github.com/vercel/next.js/blob/2848ce51d1552633119c89ab49ff7fe2e4e91c91/packages/next/src/build/webpack/loaders/next-route-loader/index.ts
346-
writedoc!(
347-
result,
348-
r#"
349-
import RouteModule from "next/dist/server/future/route-modules/pages/module"
350-
import {{ hoist }} from "next/dist/build/webpack/loaders/next-route-loader/helpers"
351-
352-
import Document from "@vercel/turbopack-next/pages/_document"
353-
import App from "@vercel/turbopack-next/pages/_app"
354-
355-
import * as userland from "INNER"
356-
357-
export default hoist(userland, "default")
358-
359-
export const getStaticProps = hoist(userland, "getStaticProps")
360-
export const getStaticPaths = hoist(userland, "getStaticPaths")
361-
export const getServerSideProps = hoist(userland, "getServerSideProps")
362-
export const config = hoist(userland, "config")
363-
export const reportWebVitals = hoist(userland, "reportWebVitals")
364-
365-
export const unstable_getStaticProps = hoist(userland, "unstable_getStaticProps")
366-
export const unstable_getStaticPaths = hoist(userland, "unstable_getStaticPaths")
367-
export const unstable_getStaticParams = hoist(userland, "unstable_getStaticParams")
368-
export const unstable_getServerProps = hoist(userland, "unstable_getServerProps")
369-
export const unstable_getServerSideProps = hoist(userland, "unstable_getServerSideProps")
370-
371-
export const routeModule = new RouteModule({{
372-
definition: {{
373-
kind: "PAGES",
374-
page: "{definition_page}",
375-
pathname: "{definition_pathname}",
376-
// The following aren't used in production, but are
377-
// required for the RouteModule constructor.
378-
bundlePath: "",
379-
filename: "",
380-
}},
381-
components: {{
382-
App,
383-
Document,
384-
}},
385-
userland,
386-
}})
387-
"#
388-
)?;
389-
390-
// When we're building the instrumentation page (only when the
391-
// instrumentation file conflicts with a page also labeled
392-
// /instrumentation) hoist the `register` method.
393-
if definition_page == "/instrumentation" || definition_page == "/src/instrumentation" {
394-
writeln!(
395-
result,
396-
r#"export const register = hoist(userland, "register")"#
397-
)?;
398-
}
399-
}
400-
PathType::PagesAPI => {
401-
// Sourced from https://github.com/vercel/next.js/blob/2848ce51d1552633119c89ab49ff7fe2e4e91c91/packages/next/src/build/webpack/loaders/next-route-loader/index.ts
402-
writedoc!(
403-
result,
404-
r#"
405-
import RouteModule from "next/dist/server/future/route-modules/pages-api/module"
406-
import {{ hoist }} from "next/dist/build/webpack/loaders/next-route-loader/helpers"
407-
408-
import * as userland from "INNER"
409-
410-
export default hoist(userland, "default")
411-
export const config = hoist(userland, "config")
412-
413-
export const routeModule = new RouteModule({{
414-
definition: {{
415-
kind: "PAGES_API",
416-
page: "{definition_page}",
417-
pathname: "{definition_pathname}",
418-
// The following aren't used in production, but are
419-
// required for the RouteModule constructor.
420-
bundlePath: "",
421-
filename: "",
422-
}},
423-
userland,
424-
}})
425-
"#
426-
)?;
427-
}
428-
_ => bail!("Invalid path type"),
429-
};
430-
431-
let file = File::from(result.build());
432-
433-
let asset = VirtualSource::new(
434-
source.ident().path().join(match path_type {
435-
PathType::Page => "pages-entry.tsx".to_string(),
436-
PathType::PagesAPI => "pages-api-entry.tsx".to_string(),
437-
_ => bail!("Invalid path type"),
438-
}),
439-
AssetContent::file(file.into()),
440-
);
441-
let ssr_module = ssr_module_context.process(
442-
Vc::upcast(asset),
443-
Value::new(ReferenceType::Internal(Vc::cell(indexmap! {
444-
"INNER".to_string() => ssr_module,
445-
}))),
446-
);
447-
448310
let client_module = create_page_loader_entry_module(client_module_context, source, pathname);
449311

450312
let Some(client_module) =

packages/next-swc/crates/next-core/js/src/entry/server-renderer.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// the other imports
33
import startHandler from '../internal/page-server-handler'
44

5-
import Document from '@vercel/turbopack-next/pages/_document'
65
import App from '@vercel/turbopack-next/pages/_app'
6+
import Document from '@vercel/turbopack-next/pages/_document'
77

88
import chunkGroup from 'INNER_CLIENT_CHUNK_GROUP'
99

packages/next-swc/crates/next-core/src/util.rs

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ use crate::next_config::{NextConfig, OutputType};
2929
#[derive(Debug, Clone, Copy, PartialEq, Eq, TaskInput)]
3030
pub enum PathType {
3131
Page,
32-
PagesAPI,
3332
Data,
3433
}
3534

packages/next/src/build/entries.ts

+4-14
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ import { fileExists } from '../lib/file-exists'
5555
import { getRouteLoaderEntry } from './webpack/loaders/next-route-loader'
5656
import { isInternalComponent } from '../lib/is-internal-component'
5757
import { isStaticMetadataRouteFile } from '../lib/metadata/is-metadata-route'
58-
import { RouteKind } from '../server/future/route-kind'
59-
import { encodeToBase64 } from './webpack/loaders/utils'
6058

6159
export async function getStaticInfoIncludingLayouts({
6260
isInsideAppDir,
@@ -591,31 +589,23 @@ export async function createEntrypoints(
591589
assetPrefix: config.assetPrefix,
592590
nextConfigOutput: config.output,
593591
preferredRegion: staticInfo.preferredRegion,
594-
middlewareConfig: encodeToBase64(staticInfo.middleware || {}),
592+
middlewareConfig: Buffer.from(
593+
JSON.stringify(staticInfo.middleware || {})
594+
).toString('base64'),
595595
})
596596
} else if (isInstrumentationHookFile(page) && pagesType === 'root') {
597597
server[serverBundlePath.replace('src/', '')] = {
598598
import: absolutePagePath,
599599
// the '../' is needed to make sure the file is not chunked
600600
filename: `../${INSTRUMENTATION_HOOK_FILENAME}.js`,
601601
}
602-
} else if (isAPIRoute(page)) {
603-
server[serverBundlePath] = [
604-
getRouteLoaderEntry({
605-
kind: RouteKind.PAGES_API,
606-
page,
607-
absolutePagePath,
608-
preferredRegion: staticInfo.preferredRegion,
609-
middlewareConfig: staticInfo.middleware || {},
610-
}),
611-
]
612602
} else if (
603+
!isAPIRoute(page) &&
613604
!isMiddlewareFile(page) &&
614605
!isInternalComponent(absolutePagePath)
615606
) {
616607
server[serverBundlePath] = [
617608
getRouteLoaderEntry({
618-
kind: RouteKind.PAGES,
619609
page,
620610
pages,
621611
absolutePagePath,

0 commit comments

Comments
 (0)