Unverified Commit 88084e6b authored by Shu Ding's avatar Shu Ding Committed by GitHub

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-L14Co-authored-by: 's avatarkodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
parent 9313c51b
...@@ -16,6 +16,7 @@ import { getProxiedPluginState } from '../../build-context' ...@@ -16,6 +16,7 @@ import { getProxiedPluginState } from '../../build-context'
import { nonNullable } from '../../../lib/non-nullable' import { nonNullable } from '../../../lib/non-nullable'
import { WEBPACK_LAYERS } from '../../../lib/constants' import { WEBPACK_LAYERS } from '../../../lib/constants'
import { normalizePagePath } from '../../../shared/lib/page-path/normalize-page-path'
interface Options { interface Options {
dev: boolean dev: boolean
...@@ -394,12 +395,18 @@ export class ClientReferenceManifestPlugin { ...@@ -394,12 +395,18 @@ export class ClientReferenceManifestPlugin {
const json = JSON.stringify(mergedManifest) const json = JSON.stringify(mergedManifest)
const pagePath = groupName.replace(/%5F/g, '_') const pagePath = groupName.replace(/%5F/g, '_')
assets['server/' + pagePath + '_' + CLIENT_REFERENCE_MANIFEST + '.js'] = const pageBundlePath = normalizePagePath(pagePath.slice('app'.length))
new sources.RawSource( assets[
`globalThis.__RSC_MANIFEST=(globalThis.__RSC_MANIFEST||{});globalThis.__RSC_MANIFEST[${JSON.stringify( 'server/app' +
pagePath.slice('app'.length) pageBundlePath +
)}]=${JSON.stringify(json)}` '_' +
) as unknown as webpack.sources.RawSource CLIENT_REFERENCE_MANIFEST +
'.js'
] = new sources.RawSource(
`globalThis.__RSC_MANIFEST=(globalThis.__RSC_MANIFEST||{});globalThis.__RSC_MANIFEST[${JSON.stringify(
pagePath.slice('app'.length)
)}]=${JSON.stringify(json)}`
) as unknown as webpack.sources.RawSource
if (pagePath === 'app/not-found') { if (pagePath === 'app/not-found') {
// Create a separate special manifest for the root not-found page. // Create a separate special manifest for the root not-found page.
......
import { Normalizers } from '../../normalizers' import { Normalizers } from '../../normalizers'
import { Normalizer } from '../../normalizer' import { Normalizer } from '../../normalizer'
import { PrefixingNormalizer } from '../../prefixing-normalizer' import { PrefixingNormalizer } from '../../prefixing-normalizer'
import { normalizePagePath } from '../../../../../shared/lib/page-path/normalize-page-path'
export class AppBundlePathNormalizer extends PrefixingNormalizer { export class AppBundlePathNormalizer extends PrefixingNormalizer {
constructor() { constructor() {
...@@ -8,7 +9,7 @@ export class AppBundlePathNormalizer extends PrefixingNormalizer { ...@@ -8,7 +9,7 @@ export class AppBundlePathNormalizer extends PrefixingNormalizer {
} }
public normalize(page: string): string { public normalize(page: string): string {
return super.normalize(page) return super.normalize(normalizePagePath(page))
} }
} }
......
...@@ -21,6 +21,11 @@ createNextDescribe( ...@@ -21,6 +21,11 @@ createNextDescribe(
expect(await res.text()).toInclude('Hello') expect(await res.text()).toInclude('Hello')
}) })
it('should handle /index routes correctly', async () => {
const appHtml = await next.render('/index')
expect(appHtml).toContain('the /index route')
})
if ((globalThis as any).isNextDev) { if ((globalThis as any).isNextDev) {
it('should resolve module without error in edge runtime', async () => { it('should resolve module without error in edge runtime', async () => {
const logs = [] const logs = []
......
export default function Page() {
return <p>the /index route</p>
}
export const runtime = 'edge'
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