Unverified Commit da84abc5 authored by Shu Ding's avatar Shu Ding Committed by GitHub

Fix chunk path resolution (#38162)

The `chunkFilenameMap` should take priority over the webpack built-in one here.

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
parent 70c0b208
...@@ -137,7 +137,10 @@ export class FlightManifestPlugin { ...@@ -137,7 +137,10 @@ export class FlightManifestPlugin {
chunks: appDir chunks: appDir
? chunk.ids.map((chunkId: string) => { ? chunk.ids.map((chunkId: string) => {
return ( return (
chunkId + ':' + chunk.name + (dev ? '' : '-' + chunk.hash) chunkId +
':' +
(chunk.name || chunkId) +
(dev ? '' : '-' + chunk.hash)
) )
}) })
: [], : [],
......
...@@ -14,7 +14,7 @@ const chunkFilenameMap = {} ...@@ -14,7 +14,7 @@ const chunkFilenameMap = {}
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
__webpack_require__.u = (chunkId) => { __webpack_require__.u = (chunkId) => {
return getChunkScriptFilename(chunkId) || chunkFilenameMap[chunkId] return chunkFilenameMap[chunkId] || getChunkScriptFilename(chunkId)
} }
// Ignore the module ID transform in client. // Ignore the module ID transform in client.
......
export default function LazyComponent() {
return (
<>
<p>hello from lazy</p>
</>
)
}
import { ClientComponent } from './test.client.js'
export default function DashboardIndexPage() { export default function DashboardIndexPage() {
return ( return (
<> <>
<p>hello from app/dashboard/index</p> <p>hello from app/dashboard/index</p>
<ClientComponent />
</> </>
) )
} }
import { useState, lazy } from 'react'
const Lazy = lazy(() => import('./lazy.client.js'))
export function ClientComponent() {
let [state] = useState('client')
return (
<>
<Lazy />
<p className="hi">hello from modern the {state}</p>
</>
)
}
...@@ -62,6 +62,11 @@ describe('views dir', () => { ...@@ -62,6 +62,11 @@ describe('views dir', () => {
expect(html).toContain('hello from app/dashboard/index') expect(html).toContain('hello from app/dashboard/index')
}) })
it('should load chunks generated via async import correctly', async () => {
const html = await renderViaHTTP(next.url, '/dashboard/index')
expect(html).toContain('hello from lazy')
})
it('should include layouts when no direct parent layout', async () => { it('should include layouts when no direct parent layout', async () => {
const html = await renderViaHTTP(next.url, '/dashboard/integrations') const html = await renderViaHTTP(next.url, '/dashboard/integrations')
const $ = cheerio.load(html) const $ = cheerio.load(html)
......
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