Skip to content

Commit 8bec06a

Browse files
committed
what happens if we delete this...
1 parent 1b9e048 commit 8bec06a

File tree

2 files changed

+4
-70
lines changed

2 files changed

+4
-70
lines changed

packages/next/src/server/lib/router-utils/resolve-routes.ts

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import type { UnwrapPromise } from '../../../lib/coalesced-function'
99
import type { NextUrlWithParsedQuery } from '../../request-meta'
1010

1111
import url from 'url'
12-
import path from 'node:path'
1312
import setupDebug from 'next/dist/compiled/debug'
1413
import { getCloneableBody } from '../../body-streams'
1514
import { filterReqHeaders, ipcForbiddenHeaders } from '../server-ipc/utils'
@@ -26,9 +25,6 @@ import { pathHasPrefix } from '../../../shared/lib/router/utils/path-has-prefix'
2625
import { detectDomainLocale } from '../../../shared/lib/i18n/detect-domain-locale'
2726
import { normalizeLocalePath } from '../../../shared/lib/i18n/normalize-locale-path'
2827
import { removePathPrefix } from '../../../shared/lib/router/utils/remove-path-prefix'
29-
import { NextDataPathnameNormalizer } from '../../normalizers/request/next-data'
30-
import { BasePathPathnameNormalizer } from '../../normalizers/request/base-path'
31-
import { PostponedPathnameNormalizer } from '../../normalizers/request/postponed'
3228

3329
import { addRequestMeta } from '../../request-meta'
3430
import {
@@ -65,9 +61,6 @@ export function getResolveRoutes(
6561
Partial<Redirect>
6662

6763
const routes: Route[] = [
68-
// _next/data with middleware handling
69-
{ match: () => ({}), name: 'middleware_next_data' },
70-
7164
...(opts.minimalMode ? [] : fsChecker.headers),
7265
...(opts.minimalMode ? [] : fsChecker.redirects),
7366

@@ -296,17 +289,6 @@ export function getResolveRoutes(
296289
}
297290
}
298291

299-
const normalizers = {
300-
basePath:
301-
config.basePath && config.basePath !== '/'
302-
? new BasePathPathnameNormalizer(config.basePath)
303-
: undefined,
304-
data: new NextDataPathnameNormalizer(fsChecker.buildId),
305-
postponed: config.experimental.ppr
306-
? new PostponedPathnameNormalizer()
307-
: undefined,
308-
}
309-
310292
async function handleRoute(
311293
route: (typeof routes)[0]
312294
): Promise<UnwrapPromise<ReturnType<typeof resolveRoutes>> | void> {
@@ -375,41 +357,6 @@ export function getResolveRoutes(
375357
}
376358
}
377359

378-
if (route.name === 'middleware_next_data' && parsedUrl.pathname) {
379-
if (fsChecker.getMiddlewareMatchers()?.length) {
380-
let normalized = parsedUrl.pathname
381-
382-
// Remove the base path if it exists.
383-
const hadBasePath = normalizers.basePath?.match(parsedUrl.pathname)
384-
if (hadBasePath && normalizers.basePath) {
385-
normalized = normalizers.basePath.normalize(normalized, true)
386-
}
387-
388-
let updated = false
389-
if (normalizers.data.match(normalized)) {
390-
updated = true
391-
parsedUrl.query.__nextDataReq = '1'
392-
normalized = normalizers.data.normalize(normalized, true)
393-
} else if (normalizers.postponed?.match(normalized)) {
394-
updated = true
395-
normalized = normalizers.postponed.normalize(normalized, true)
396-
}
397-
398-
// If we updated the pathname, and it had a base path, re-add the
399-
// base path.
400-
if (updated) {
401-
if (hadBasePath) {
402-
normalized = path.posix.join(config.basePath, normalized)
403-
}
404-
405-
// Re-add the trailing slash (if required).
406-
normalized = maybeAddTrailingSlash(normalized)
407-
408-
parsedUrl.pathname = normalized
409-
}
410-
}
411-
}
412-
413360
if (route.name === 'check_fs') {
414361
const pathname = parsedUrl.pathname || ''
415362

@@ -743,6 +690,7 @@ export function getResolveRoutes(
743690
}
744691
}
745692
didRewrite = true
693+
console.log('setting pathname 775', parsedDestination.pathname)
746694
parsedUrl.pathname = parsedDestination.pathname
747695
Object.assign(parsedUrl.query, parsedDestination.query)
748696
}

packages/next/src/shared/lib/i18n/normalize-locale-path.ts

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,8 @@ export function normalizeLocalePath(
1717
locales?: string[]
1818
): PathLocale {
1919
let detectedLocale: string | undefined
20-
const isDataRoute = pathname.startsWith('/_next/data')
21-
22-
// Create a pathname for locale detection, removing /_next/data/[buildId] if present
23-
// This is because locale detection relies on path splitting and so the first part
24-
// should be the locale.
25-
const pathNameNoDataPrefix = isDataRoute
26-
? pathname.replace(/^\/_next\/data\/[^/]+/, '')
27-
: pathname
28-
29-
// Split the path for locale detection
30-
const pathnameParts = pathNameNoDataPrefix.split('/')
20+
// first item will be empty string from splitting at first char
21+
const pathnameParts = pathname.split('/')
3122

3223
;(locales || []).some((locale) => {
3324
if (
@@ -36,17 +27,12 @@ export function normalizeLocalePath(
3627
) {
3728
detectedLocale = locale
3829
pathnameParts.splice(1, 1)
30+
pathname = pathnameParts.join('/') || '/'
3931
return true
4032
}
4133
return false
4234
})
4335

44-
// For non-data routes, we return the path with the locale stripped out.
45-
// For data routes, we keep the path as is, since we only want to extract the locale.
46-
if (detectedLocale && !isDataRoute) {
47-
pathname = pathnameParts.join('/') || '/'
48-
}
49-
5036
return {
5137
pathname,
5238
detectedLocale,

0 commit comments

Comments
 (0)