Unverified Commit 0fb3284d authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

Use resolved url in flight entry loader (#40697)

If there's any resolve alias in webpack config, an aliased resource url will error with `require.resolve` usage in flight manifest plugin, we need to resolve the absolute resource url first then pass down to flight manifest


## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see `contributing.md`
parent 642d52e1
...@@ -41,9 +41,16 @@ export default async function transformSource(this: any): Promise<string> { ...@@ -41,9 +41,16 @@ export default async function transformSource(this: any): Promise<string> {
` `
const buildInfo = getModuleBuildInfo(this._module) const buildInfo = getModuleBuildInfo(this._module)
const resolve = this.getResolve()
// Resolve to absolute resource url for flight manifest to collect and use to determine client components
const resolvedRequests = await Promise.all(
requests.map(async (r) => await resolve(this.rootContext, r))
)
buildInfo.rsc = { buildInfo.rsc = {
type: RSC_MODULE_TYPES.client, type: RSC_MODULE_TYPES.client,
requests, requests: resolvedRequests,
} }
return code return code
......
...@@ -112,7 +112,7 @@ export class FlightManifestPlugin { ...@@ -112,7 +112,7 @@ export class FlightManifestPlugin {
if (mod.resource === '' && mod.buildInfo.rsc) { if (mod.resource === '' && mod.buildInfo.rsc) {
const { requests = [] } = mod.buildInfo.rsc const { requests = [] } = mod.buildInfo.rsc
requests.forEach((r: string) => { requests.forEach((r: string) => {
clientRequestsSet.add(require.resolve(r)) clientRequestsSet.add(r)
}) })
} }
} }
......
import { createNext, FileRef } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
import { renderViaHTTP } from 'next-test-utils'
import path from 'path'
describe('app-dir alias handling', () => {
if ((global as any).isNextDeploy) {
it('should skip next deploy for now', () => {})
return
}
if (process.env.NEXT_TEST_REACT_VERSION === '^17') {
it('should skip for react v17', () => {})
return
}
let next: NextInstance
beforeAll(async () => {
next = await createNext({
files: new FileRef(path.join(__dirname, 'app-alias')),
dependencies: {
react: 'experimental',
'react-dom': 'experimental',
typescript: 'latest',
'@types/react': 'latest',
'@types/node': 'latest',
},
})
})
afterAll(() => next.destroy())
it('should handle typescript paths alias correctly', async () => {
const html = await renderViaHTTP(next.url, '/button')
expect(html).toContain('<button>click</button>')
})
})
import Button from '@/ui/button'
export default function page() {
return <Button>click</Button>
}
module.exports = {
experimental: {
appDir: true,
serverComponents: true,
legacyBrowsers: false,
browsersListForSwc: true,
},
}
{
"compilerOptions": {
"target": "ES6",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"baseUrl": ".",
"paths": {
"@/ui/*": ["ui/*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}
export default function Button(props: any) {
return <button {...props} />
}
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