From 712d45f7608dde47aa8021e45734c1cea4bb82c2 Mon Sep 17 00:00:00 2001 From: Shu Ding Date: Tue, 22 Nov 2022 15:03:46 +0100 Subject: [PATCH] Fix app routes are not correctly matched when src directory is used (#43234) When creating the client entries, the `src/` prefix shouldn't be included in the entrypoint's name. Closes #42874. ## Bug - [x] Related issues linked using `fixes #number` - [x] Integration tests added - [ ] Errors have a 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 a helpful link attached, see `contributing.md` ## Documentation / Examples - [ ] Make sure the linting passes by running `pnpm build && pnpm lint` - [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md) --- .../webpack/plugins/flight-client-entry-plugin.ts | 4 +++- test/e2e/app-dir/app-alias.test.ts | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/next/build/webpack/plugins/flight-client-entry-plugin.ts b/packages/next/build/webpack/plugins/flight-client-entry-plugin.ts index 2df42a8d90533..77545f5c2b85f 100644 --- a/packages/next/build/webpack/plugins/flight-client-entry-plugin.ts +++ b/packages/next/build/webpack/plugins/flight-client-entry-plugin.ts @@ -203,7 +203,9 @@ export class FlightClientEntryPlugin { : entryRequest // Replace file suffix as `.js` will be added. - const bundlePath = relativeRequest.replace(/\.(js|ts)x?$/, '') + const bundlePath = relativeRequest + .replace(/\.(js|ts)x?$/, '') + .replace(/^src[\\/]/, '') promises.push( this.injectClientEntryAndSSRModules({ diff --git a/test/e2e/app-dir/app-alias.test.ts b/test/e2e/app-dir/app-alias.test.ts index 3b8c434d05079..e857c483236ba 100644 --- a/test/e2e/app-dir/app-alias.test.ts +++ b/test/e2e/app-dir/app-alias.test.ts @@ -3,6 +3,7 @@ import { NextInstance } from 'test/lib/next-modes/base' import { renderViaHTTP } from 'next-test-utils' import webdriver from 'next-webdriver' import path from 'path' +import { readJSON } from 'fs-extra' describe('app-dir alias handling', () => { if ((global as any).isNextDeploy) { @@ -41,4 +42,15 @@ describe('app-dir alias handling', () => { .getComputedCss('font-size') expect(fontSize).toBe('50px') }) + + if (!(global as any).isNextDev) { + it('should generate app-build-manifest correctly', async () => { + // Remove other page CSS files: + const manifest = await readJSON( + path.join(next.testDir, '.next', 'app-build-manifest.json') + ) + + expect(manifest.pages).not.toBeEmptyObject() + }) + } })