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

Use resolved url in flight entry loader #40697

Merged
merged 2 commits into from Sep 20, 2022
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
Expand Up @@ -41,9 +41,16 @@ export default async function transformSource(this: any): Promise<string> {
`

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 = {
type: RSC_MODULE_TYPES.client,
requests,
requests: resolvedRequests,
}

return code
Expand Down
Expand Up @@ -112,7 +112,7 @@ export class FlightManifestPlugin {
if (mod.resource === '' && mod.buildInfo.rsc) {
const { requests = [] } = mod.buildInfo.rsc
requests.forEach((r: string) => {
clientRequestsSet.add(require.resolve(r))
clientRequestsSet.add(r)
})
}
}
Expand Down
37 changes: 37 additions & 0 deletions test/e2e/app-dir/app-alias.test.ts
@@ -0,0 +1,37 @@
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>')
})
})
5 changes: 5 additions & 0 deletions test/e2e/app-dir/app-alias/app/button/page.tsx
@@ -0,0 +1,5 @@
import Button from '@/ui/button'

export default function page() {
return <Button>click</Button>
}
8 changes: 8 additions & 0 deletions test/e2e/app-dir/app-alias/next.config.js
@@ -0,0 +1,8 @@
module.exports = {
experimental: {
appDir: true,
serverComponents: true,
legacyBrowsers: false,
browsersListForSwc: true,
},
}
24 changes: 24 additions & 0 deletions test/e2e/app-dir/app-alias/tsconfig.json
@@ -0,0 +1,24 @@
{
"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"]
}
3 changes: 3 additions & 0 deletions test/e2e/app-dir/app-alias/ui/button.tsx
@@ -0,0 +1,3 @@
export default function Button(props: any) {
return <button {...props} />
}