Skip to content

Commit 88084e6

Browse files
Fix bundle path normalization for /index routes (#52650)
We have some special bundle path handling logic for `/index` routes in `normalizePagePath`, which is missing in the new `AppBundlePathNormalizer`. This already broke `/index/page.js` in dev in the past, and now become noticeable in prod as well because of the manifest change. https://github.com/vercel/next.js/blob/b98469c86b74b06b55fc4c59bcf87d034e1919f1/packages/next/src/shared/lib/page-path/normalize-page-path.ts#L5-L14 Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent 9313c51 commit 88084e6

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

packages/next/src/build/webpack/plugins/flight-manifest-plugin.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { getProxiedPluginState } from '../../build-context'
1616

1717
import { nonNullable } from '../../../lib/non-nullable'
1818
import { WEBPACK_LAYERS } from '../../../lib/constants'
19+
import { normalizePagePath } from '../../../shared/lib/page-path/normalize-page-path'
1920

2021
interface Options {
2122
dev: boolean
@@ -394,12 +395,18 @@ export class ClientReferenceManifestPlugin {
394395
const json = JSON.stringify(mergedManifest)
395396

396397
const pagePath = groupName.replace(/%5F/g, '_')
397-
assets['server/' + pagePath + '_' + CLIENT_REFERENCE_MANIFEST + '.js'] =
398-
new sources.RawSource(
399-
`globalThis.__RSC_MANIFEST=(globalThis.__RSC_MANIFEST||{});globalThis.__RSC_MANIFEST[${JSON.stringify(
400-
pagePath.slice('app'.length)
401-
)}]=${JSON.stringify(json)}`
402-
) as unknown as webpack.sources.RawSource
398+
const pageBundlePath = normalizePagePath(pagePath.slice('app'.length))
399+
assets[
400+
'server/app' +
401+
pageBundlePath +
402+
'_' +
403+
CLIENT_REFERENCE_MANIFEST +
404+
'.js'
405+
] = new sources.RawSource(
406+
`globalThis.__RSC_MANIFEST=(globalThis.__RSC_MANIFEST||{});globalThis.__RSC_MANIFEST[${JSON.stringify(
407+
pagePath.slice('app'.length)
408+
)}]=${JSON.stringify(json)}`
409+
) as unknown as webpack.sources.RawSource
403410

404411
if (pagePath === 'app/not-found') {
405412
// Create a separate special manifest for the root not-found page.

packages/next/src/server/future/normalizers/built/app/app-bundle-path-normalizer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import { Normalizers } from '../../normalizers'
22
import { Normalizer } from '../../normalizer'
33
import { PrefixingNormalizer } from '../../prefixing-normalizer'
4+
import { normalizePagePath } from '../../../../../shared/lib/page-path/normalize-page-path'
45

56
export class AppBundlePathNormalizer extends PrefixingNormalizer {
67
constructor() {
78
super('app')
89
}
910

1011
public normalize(page: string): string {
11-
return super.normalize(page)
12+
return super.normalize(normalizePagePath(page))
1213
}
1314
}
1415

test/e2e/app-dir/app-edge/app-edge.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ createNextDescribe(
2121
expect(await res.text()).toInclude('Hello')
2222
})
2323

24+
it('should handle /index routes correctly', async () => {
25+
const appHtml = await next.render('/index')
26+
expect(appHtml).toContain('the /index route')
27+
})
28+
2429
if ((globalThis as any).isNextDev) {
2530
it('should resolve module without error in edge runtime', async () => {
2631
const logs = []
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default function Page() {
2+
return <p>the /index route</p>
3+
}
4+
5+
export const runtime = 'edge'

0 commit comments

Comments
 (0)