Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bundle path normalization for /index routes #52650

Merged
merged 2 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { getProxiedPluginState } from '../../build-context'

import { nonNullable } from '../../../lib/non-nullable'
import { WEBPACK_LAYERS } from '../../../lib/constants'
import { normalizePagePath } from '../../../shared/lib/page-path/normalize-page-path'

interface Options {
dev: boolean
Expand Down Expand Up @@ -394,12 +395,18 @@ export class ClientReferenceManifestPlugin {
const json = JSON.stringify(mergedManifest)

const pagePath = groupName.replace(/%5F/g, '_')
assets['server/' + pagePath + '_' + 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
const pageBundlePath = normalizePagePath(pagePath.slice('app'.length))
assets[
'server/app' +
pageBundlePath +
'_' +
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') {
// Create a separate special manifest for the root not-found page.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { Normalizers } from '../../normalizers'
import { Normalizer } from '../../normalizer'
import { PrefixingNormalizer } from '../../prefixing-normalizer'
import { normalizePagePath } from '../../../../../shared/lib/page-path/normalize-page-path'

export class AppBundlePathNormalizer extends PrefixingNormalizer {
constructor() {
super('app')
}

public normalize(page: string): string {
return super.normalize(page)
return super.normalize(normalizePagePath(page))
}
}

Expand Down
5 changes: 5 additions & 0 deletions test/e2e/app-dir/app-edge/app-edge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ createNextDescribe(
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) {
it('should resolve module without error in edge runtime', async () => {
const logs = []
Expand Down
5 changes: 5 additions & 0 deletions test/e2e/app-dir/app-edge/app/index/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default function Page() {
return <p>the /index route</p>
}

export const runtime = 'edge'