Unverified Commit 51733567 authored by hrmny's avatar hrmny Committed by GitHub

perf(turbopack): only build last parallel route (#67588)

### What?

This partially reverts #67222, it's unnecessary to build all parallel
routes and also seems to have a higher overhead than I thought.
parent e15549c7
...@@ -81,6 +81,7 @@ import { ...@@ -81,6 +81,7 @@ import {
import { FAST_REFRESH_RUNTIME_RELOAD } from './messages' import { FAST_REFRESH_RUNTIME_RELOAD } from './messages'
import { generateEncryptionKeyBase64 } from '../app-render/encryption-utils' import { generateEncryptionKeyBase64 } from '../app-render/encryption-utils'
import { isAppPageRouteDefinition } from '../route-definitions/app-page-route-definition' import { isAppPageRouteDefinition } from '../route-definitions/app-page-route-definition'
import { normalizeAppPath } from '../../shared/lib/router/utils/app-paths'
const wsServer = new ws.Server({ noServer: true }) const wsServer = new ws.Server({ noServer: true })
const isTestMode = !!( const isTestMode = !!(
...@@ -784,17 +785,27 @@ export async function createHotReloaderTurbopack( ...@@ -784,17 +785,27 @@ export async function createHotReloaderTurbopack(
opts.appDir opts.appDir
)) ))
const page = routeDef.page
const pathname = definition?.pathname ?? inputPage
let pages = appPaths ?? [page]
// If the route is actually an app page route, then we should have access // If the route is actually an app page route, then we should have access
// to the app route definition, and therefore, the appPaths from it. // to the app route definition, and therefore, the appPaths from it.
if (!appPaths && definition && isAppPageRouteDefinition(definition)) { if (!appPaths && definition && isAppPageRouteDefinition(definition)) {
pages = definition.appPaths appPaths = definition.appPaths
} }
let page = routeDef.page
if (appPaths) {
const normalizedPage = normalizeAppPath(page)
// filter out paths that are not exact matches (e.g. catchall)
const matchingAppPaths = appPaths.filter(
(path) => normalizeAppPath(path) === normalizedPage
)
// the last item in the array is the root page, if there are parallel routes
page = matchingAppPaths[matchingAppPaths.length - 1]
}
const pathname = definition?.pathname ?? inputPage
if (page === '/_error') { if (page === '/_error') {
let finishBuilding = startBuilding(pathname, requestUrl, false) let finishBuilding = startBuilding(pathname, requestUrl, false)
try { try {
...@@ -823,17 +834,11 @@ export async function createHotReloaderTurbopack( ...@@ -823,17 +834,11 @@ export async function createHotReloaderTurbopack(
await currentEntriesHandling await currentEntriesHandling
const isInsideAppDir = routeDef.bundlePath.startsWith('app/') const isInsideAppDir = routeDef.bundlePath.startsWith('app/')
const finishBuilding = startBuilding(pathname, requestUrl, false)
try {
// we need to build all parallel routes, so we loop over them here
/* eslint-disable-next-line @typescript-eslint/no-shadow -- intentionally shadowed*/
for (const page of pages) {
const normalizedAppPage = normalizedPageToTurbopackStructureRoute( const normalizedAppPage = normalizedPageToTurbopackStructureRoute(
page, page,
extname(routeDef.filename) extname(routeDef.filename)
) )
const route = isInsideAppDir const route = isInsideAppDir
? currentEntrypoints.app.get(normalizedAppPage) ? currentEntrypoints.app.get(normalizedAppPage)
: currentEntrypoints.page.get(page) : currentEntrypoints.page.get(page)
...@@ -855,6 +860,8 @@ export async function createHotReloaderTurbopack( ...@@ -855,6 +860,8 @@ export async function createHotReloaderTurbopack(
throw new Error(`mis-matched route type: isApp && page for ${page}`) throw new Error(`mis-matched route type: isApp && page for ${page}`)
} }
const finishBuilding = startBuilding(pathname, requestUrl, false)
try {
await handleRouteType({ await handleRouteType({
dev: true, dev: true,
page, page,
...@@ -876,7 +883,6 @@ export async function createHotReloaderTurbopack( ...@@ -876,7 +883,6 @@ export async function createHotReloaderTurbopack(
}, },
}, },
}) })
}
} finally { } finally {
finishBuilding() finishBuilding()
} }
......
...@@ -21,5 +21,5 @@ ...@@ -21,5 +21,5 @@
"target": "ES2017" "target": "ES2017"
}, },
"include": ["next-env.d.ts", ".next/types/**/*.ts", "**/*.ts", "**/*.tsx"], "include": ["next-env.d.ts", ".next/types/**/*.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"] "exclude": ["node_modules", "**/*.test.ts"]
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment